Skip to main content
Module

x/canvas/mod.ts>Image

Canvas API for Deno, ported from canvaskit-wasm (Skia).
Latest
interface Image
implements EmbindObject<Image>
import { type Image } from "https://deno.land/x/canvas@v1.4.1/mod.ts";

See SkImage.h for more information on this class.

Methods

encodeToBytes(fmt?: EncodedImageFormat, quality?: number): Uint8Array | null

Encodes this image's pixels to the specified format and returns them. Must be built with the specified codec. If the options are unspecified, sensible defaults will be chosen.

getColorSpace(): ColorSpace

Returns the color space associated with this object. It is the user's responsibility to call delete() on this after it has been used.

getImageInfo(): PartialImageInfo

Returns the width, height, colorType and alphaType associated with this image. Colorspace is separate so as to not accidentally leak that memory.

height(): number

Return the height in pixels of the image.

makeCopyWithDefaultMipmaps(): Image

Returns an Image with the same "base" pixels as the this image, but with mipmap levels automatically generated and attached.

makeShaderCubic(
B: number,
C: number,
localMatrix?: InputMatrix,
): Shader

Returns this image as a shader with the specified tiling. It will use cubic sampling.

makeShaderOptions(
localMatrix?: InputMatrix,
): Shader

Returns this image as a shader with the specified tiling. It will use cubic sampling.

readPixels(
srcX: number,
srcY: number,
imageInfo: ImageInfo,
dest?: MallocObj,
bytesPerRow?: number,
): Uint8Array | Float32Array | null

Returns a TypedArray containing the pixels reading starting at (srcX, srcY) and does not exceed the size indicated by imageInfo. See SkImage.h for more on the caveats.

If dest is not provided, we allocate memory equal to the provided height * the provided bytesPerRow to fill the data with.

width(): number

Return the width in pixels of the image.