ImageBitmap

An ImageBitmap represents an image texture in GPU memory, that can be drawn efficiently to the canvas via canvas.drawImage.

An ImageBitmap can be created in several ways:

An ImageBitmap is appropriate to hold images loaded from files for fast drawing. See ImageData for a similar class that gives access to the underlying pixels.

See also the ImageBitmap documentation on MDN.

ImageBitmap

Creates a new ImageBitmap with a copy of the pixels in another ImageBitmap or in an ImageData. The constructor has 4 additional, optional parameters:

source ImageBitmap|ImageData The source image pixels to copy.
x number The horizontal coordinate of the source rectangle to copy. Defaults to 0.
y number The vertical coordinate of the source rectangle to copy. Defaults to 0.
w number The width of the source rectangle to copy. Defaults to the width of the source.
h number The height of the source rectangle to copy. Defaults to the height of the source.

ImageBitmap.decode()(Uint8Array | Uint8ClampedArray | ArrayBuffer) => Promise<ImageBitmap>

Returns a new ImageBitmap, decoded from the given image bytes.

The valid input formats are JPEG, PNG and WEBP.

imageBitmap.heightnumber

The height of this ImageBitmap.

imageBitmap.widthnumber

The width of this ImageBitmap.

imageBitmap.encode()(string?, number?) => Promise<ArrayBuffer>

Encodes this ImageBitmap in a given image format and returns the bytes representing that encoding.

codec string? The image codec to use for the encoding. Valid values are "jpeg", "png" and "webp".
quality number? For the "jpeg" codec, the quality parameter is a number from 0 to 100 indicating the quality of the output image. 0 is smaller but lower quality, 100 is the highest quality but also a larger encoding.