Skip to main content

Class: OffscreenLayer2D

(abstract) Rendering.2D.OffscreenLayer2D(ctx)

Storage for a bitmap data that can be manipulated or presented on the screen.It corresponds to an OffscreenCanvas used as drawing surface.It defines the ration between actual pixels and the abstract layer dimensions.Not constructable. InkCanvas creates such layers.

Constructor

(abstract) new OffscreenLayer2D(ctx)

Parameters:
NameTypeDescription
ctxCanvasRenderingContext2D
Properties:
NameTypeDescription
widthintLayer width
heightintLayer height
boundsintThe bounds of the layer. Equals to (0, 0, width, height).
surfaceHTMLCanvasElement|OffscreenCanvasDrawing surface
ctxCanvasRenderingContext2D|OffscreenCanvasRenderingContext2DDrawing surface context

Since:

  • version 3.0

See:

Extends

Methods

blend(source, options)

Draws the content of the 'source'. The 'source' must use a texture storage.

Parameters:
NameTypeDescription
sourceRendering.2D.OffscreenLayer2DLayer to be drawn
optionsRendering.BlendOptionsBlending configuration

clear(rectopt, coloropt)

Clears layer area with a color

Parameters:
NameTypeAttributesDefaultDescription
rectCommon.Rect|Common.Color<optional>boundsArea to clear
colorCommon.Color<optional>Color.TRANSPERENT

createImageData(pixels, rect) → {ImageData}

Creates image data object

Parameters:
NameTypeDescription
pixelsUint8ClampedArrayImage data pixel values
rectCommon.Rect
Returns:

Pixels image data

Type

ImageData

draw(stroke) → Common.Rect

Draws points with a brush over the layer

Parameters:
NameTypeDescription
strokeStrokeStroke model instance
Returns:

Affected area

Type

Common.Rect

drawStroke(brush, path, color, matrixopt) → Common.Rect

Draws points with a brush over the layer

Parameters:
NameTypeAttributesDescription
brushRendering.2D.Brush2DRendering brush
pathPathBuilding.InkPath2DContours list, where contour is points list
colorCommon.ColorStroke color
matrixCommon.Matrix<optional>Transforms drawing context
Returns:

Affected area

Type

Common.Rect

fill(shape, color) → Common.Rect

Fills shape with color

Parameters:
NameTypeDescription
shapePathBuilding.PolygonArray|PathBuilding.Polygon|Polygon|RectControl points to work with it
colorCommon.ColorFill color
Returns:

Affected area

Type

Common.Rect

(async, abstract) getExportCanvas()

Overrides:

getImageData(rectopt) → {ImageData}

Read pixels data

Parameters:
NameTypeAttributesDefaultDescription
rectCommon.Rect<optional>boundsArea to read
Returns:

Pixels image data

Type

ImageData

putImageData(imageData, xopt, yopt)

Write pixels data

Parameters:
NameTypeAttributesDefaultDescription
imageDataImageDataAn ImageData object containing the array of pixel values
xint<optional>0Horizontal position (x coordinate) at which to place the image data in the destination layer
yint<optional>0Vertical position (y coordinate) at which to place the image data in the destination layer

readPixels(rectopt) → {Uint8ClampedArray}

Read pixels data

Parameters:
NameTypeAttributesDefaultDescription
rectCommon.Rect<optional>boundsArea to read
Returns:

Array of pixel values

Type

Uint8ClampedArray

resize(width, height)

Resize layer

Parameters:
NameTypeDescription
widthintNew width
heightintNew height

setTransform(matrix)

Configures ink transformation over underlying layer

Parameters:
NameTypeDescription
matrixCommon.Matrix

Overrides:

(async) toBlob(rectopt, mimeTypeopt, qualityopt) → {Blob}

Exports layer content. Compatible in web environment.

Parameters:
NameTypeAttributesDefaultDescription
rectCommon.Rect<optional>boundsArea to read
mimeTypestring<optional>image/pngSupported values are image/png, image/jpeg and image/webp.
qualityfloat<optional>0.92A Number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp.If this argument is anything else, the default values 0.92 and 0.80 are used for image/jpeg and image/webp respectively.

Overrides:

Returns:

Layer content

Type

Blob

(async) toBuffer(rectopt, mimeTypeopt, options) → {Buffer}

Exports layer content. Compatible in nodejs environment.

Parameters:
NameTypeAttributesDefaultDescription
rectCommon.Rect<optional>boundsArea to read
mimeTypestring<optional>image/pngSupported values are image/png and image/jpeg.
optionsRendering.Layer.PNGOptions|Rendering.Layer.JPEGOptions

Overrides:

Returns:

Layer content

Type

Buffer

writePixels(data, rectopt)

Write pixels data

Parameters:
NameTypeAttributesDefaultDescription
dataUint8ClampedArray|Uint8ArrayArray of pixel values
rectCommon.Rect<optional>boundsArea to write

Home