Skip to main content

Function: copyPixels()

copyPixels(source, area, createCanvas): OffscreenCanvas

Defined in: src/lib/rendering/sample/index.ts:87

Copy an area of a canvas onto a new canvas the size of the area, by reading its pixels. Reading only the area keeps this quick for GPU-backed canvases: drawing one onto another canvas can copy all of its pixels back from the GPU.

Parameters​

source​

OffscreenCanvas

area​

PixelRect

createCanvas​

CanvasFactory

Returns​

OffscreenCanvas

Example​

copyPixels(layer.canvas, { x: 10, y: 10, width: 1, height: 1 }, createOffscreenCanvas); // a 1 × 1 canvas