canvaskit-wasm 0.39 build 2026-04-29

Image

A decoded bitmap that lives inside CanvasKit. Hand a PNG/JPEG byte buffer to CK.MakeImageFromEncoded (or upload a DOM source via surface.makeImageFromTextureSource) and you get back an Image you can draw with canvas.drawImage / drawImageRect, sample as a shader via image.makeShaderOptions, or feed into image filters.

Image is a WASM object. Decode once, reuse forever, .delete() when done. The doc-page bundle's loadImage(url) helper caches by URL on window so multiple demos share a single decoded image.

Error: Line 1: Unexpected identifier

drawImage(img, x, y, paint?) blits at native size. drawImageRect(img, src, dst, paint?) scales a sub-rect of the image into a destination rect — that's how sprite atlases work.

Sampling as a shader

Wrap an image as a shader to sample it per-pixel. Useful for procedural patterns, displacement, or anywhere you'd otherwise reach for drawImageRect repeatedly.

Error: Line 1: Unexpected identifier

TileMode.Repeat tiles the chess image across the rounded rect.

Common methods

MemberArgsReturnsNotes
deletevoidFree the WASM memory.
encodeToBytesfmt?: ImageFormat, quality?: numberUint8ArrayEncode to PNG/JPEG/WebP bytes.
getColorSpaceColorSpaceColor space the image was decoded into.
getImageInfoPartialImageInfoWidth, height, color type, alpha type.
heightnumberImage height in pixels.
makeShaderCubictx, ty: TileMode, B, C: number, localMatrix?: MatrixShaderCubic-resampled shader. Highest quality, slowest.
makeShaderOptionstx, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: MatrixShaderSampled shader with explicit filter/mipmap controls.
readPixelsx, y: number, info: ImageInfo, dst?: MallocObj, bytesPerRow?: numberUint8Array | Float32Array | nullRead pixels back to JS.
widthnumberImage width in pixels.

Static factories

(on CanvasKit)

FactoryArgsReturnsNotes
CK.MakeImageFromEncodedbytes: Uint8Array | ArrayBufferImage | nullDecode PNG/JPEG/WebP. The most common entry point.
CK.MakeImageinfo: ImageInfo, pixels: Uint8Array, bytesPerRow: numberImage | nullWrap a raw pixel buffer.
CK.MakeAnimatedImageFromEncodedbytes: Uint8ArrayAnimatedImage | nullDecode an animated GIF/WebP/APNG.
CK.MakeLazyImageFromTextureSourcesrc: TexImageSource, info?: ImageInfo, srcIsPremul?: booleanImageDefer GL upload until first draw.

See also