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:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D |
Properties:
Name | Type | Description |
---|---|---|
width | int | Layer width |
height | int | Layer height |
bounds | int | The bounds of the layer. Equals to (0, 0, width, height). |
surface | HTMLCanvasElement|OffscreenCanvas | Drawing surface |
ctx | CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D | Drawing 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:
Name | Type | Description |
---|---|---|
source | Rendering.2D.OffscreenLayer2D | Layer to be drawn |
options | Rendering.BlendOptions | Blending configuration |
clear(rectopt, coloropt)
Clears layer area with a color
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rect | Common.Rect|Common.Color | <optional> | bounds | Area to clear |
color | Common.Color | <optional> | Color.TRANSPERENT |
createImageData(pixels, rect) → {ImageData}
Creates image data object
Parameters:
Name | Type | Description |
---|---|---|
pixels | Uint8ClampedArray | Image data pixel values |
rect | Common.Rect |
Returns:
Pixels image data
Type
ImageData
draw(stroke) → Common.Rect
Draws points with a brush over the layer
Parameters:
Name | Type | Description |
---|---|---|
stroke | Stroke | Stroke model instance |
Returns:
Affected area
Type
drawStroke(brush, path, color, matrixopt) → Common.Rect
Draws points with a brush over the layer
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
brush | Rendering.2D.Brush2D | Rendering brush | |
path | PathBuilding.InkPath2D | Contours list, where contour is points list | |
color | Common.Color | Stroke color | |
matrix | Common.Matrix | <optional> | Transforms drawing context |
Returns:
Affected area
Type
fill(shape, color) → Common.Rect
Fills shape with color
Parameters:
Name | Type | Description |
---|---|---|
shape | PathBuilding.PolygonArray|PathBuilding.Polygon|Polygon|Rect | Control points to work with it |
color | Common.Color | Fill color |
Returns:
Affected area
Type
(async, abstract) getExportCanvas()
Overrides:
getImageData(rectopt) → {ImageData}
Read pixels data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rect | Common.Rect | <optional> | bounds | Area to read |
Returns:
Pixels image data
Type
ImageData
putImageData(imageData, xopt, yopt)
Write pixels data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
imageData | ImageData | An ImageData object containing the array of pixel values | ||
x | int | <optional> | 0 | Horizontal position (x coordinate) at which to place the image data in the destination layer |
y | int | <optional> | 0 | Vertical position (y coordinate) at which to place the image data in the destination layer |
readPixels(rectopt) → {Uint8ClampedArray}
Read pixels data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rect | Common.Rect | <optional> | bounds | Area to read |
Returns:
Array of pixel values
Type
Uint8ClampedArray
resize(width, height)
Resize layer
Parameters:
Name | Type | Description |
---|---|---|
width | int | New width |
height | int | New height |
setTransform(matrix)
Configures ink transformation over underlying layer
Parameters:
Name | Type | Description |
---|---|---|
matrix | Common.Matrix |
Overrides:
(async) toBlob(rectopt, mimeTypeopt, qualityopt) → {Blob}
Exports layer content. Compatible in web environment.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rect | Common.Rect | <optional> | bounds | Area to read |
mimeType | string | <optional> | image/png | Supported values are image/png, image/jpeg and image/webp. |
quality | float | <optional> | 0.92 | A 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:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rect | Common.Rect | <optional> | bounds | Area to read |
mimeType | string | <optional> | image/png | Supported values are image/png and image/jpeg. |
options | Rendering.Layer.PNGOptions|Rendering.Layer.JPEGOptions |
Overrides:
Returns:
Layer content
Type
Buffer
writePixels(data, rectopt)
Write pixels data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data | Uint8ClampedArray|Uint8Array | Array of pixel values | ||
rect | Common.Rect | <optional> | bounds | Area to write |