Surface

Constructors

new

Surface

(width: number, height: number, options?: SurfaceCreateOptions, canvas?: HTMLCanvasElement)

Creates a new instance of the surface with certain parameters

Surface

.

fromImage

(image: HTMLImageElement | ImageBitmap, rect: TRect, options?: SurfaceCreateOptions)

Creates a new instance of surface from an image

Surface

.

fromImages

(image: HTMLImageElement[], rect: TRect, rows: number = 1, cols: number = -1, options?: SurfaceCreateOptions)

Creates a new instance of surface from an images

Surface

.

fromCanvas

(canvas: HTMLCanvasElement, options?: SurfaceCreateOptions)

Creates a new instance of surface from an exist canvas

Surface

.

default

Creates a new instance of surface with 1x1px size

Surface

.

combine

(surfaces: ISurface[], rows: number = 1, cols: number = -1, options?: SurfaceCreateOptions)

Combines surfaces in new instance of surface


Properties

width

:

number

get

Gets a width of the surface

height

:

number

get

Gets a height of the surface

rect

:

TRect

get

Gets a distribute rect of the surface

imageRendering

:

'auto' | 'pixelated'

get set

Gets or sets an image scaling method linear interpolation or nearest neighbor

pixels

:

Pixels

get

Gets object for a pixel manipulation

draw

:

Draw

get

Gets object for a draw (Not recommended use this property directly)


Methods

clear

(rect?: TRect) ⇨ void

Clears a surface

fill

(color: string) ⇨ void

Fills a surface a specified color

blit

(surface: ISurface, rect: TRect | TPoint, srcRect?: TRect) ⇨ void

Copies a specified surface bitmap on the current surface in specified rect

blita

(alpha: number, surface: ISurface, rect: TRect | TPoint, srcRect?: TRect) ⇨ void

Copies a specified surface bitmap on the current surface in specified rect

extract

(rect: TRect) ⇨ void

Creates new instance of the surface by extracted a specified rectangle from original surface

zoom

(index: number) ⇨ void

Scales the surface by both axises in a specified value

flip

(position: 'x' | 'y' | 'xy') ⇨ void

Flips the surface in a specified position

rotate

(deg: number, pivote?: TPivote) ⇨ void

Rotates the surface in a specified angle

resize

(width: number, height: number) ⇨ void

Resizes the surface in a specified width and height

setCanvasSize

(width: number, height: number, shiftToCenter: boolean = true) ⇨ void

Sets a canvas size of the surface a specified width and height

mix

(method: GlobalCompositeOperation, surface: ISurface, rect: TRect | TPoint, srcRect?: TRect) ⇨ void

Does composite operation on the original surface

createImage

(type: string, quality: any) ⇨ Promise

Create a HTML image element from the surface

toDataURL

(type: string, quality: any) ⇨ string

Create a data URL from the surface

toPattern

(type: repetition: "repeat" | "repeat-x" | "repeat-y" | "no-repeat") ⇨ CanvasPattern

Creates a pattern from the surface

toBitmap

() ⇨ Bitmap

Creates a bitmap from the surface

save

(type: string, quality: any) ⇨ Promise<Blob | null>

Creates a Blob object from the surface

createMask

() ⇨ PixelMask

Creates a pixel mask object from the surface

clone

() ⇨ Surface

Creates a copy of the original surface