HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

createImageBitmap

Description

The createImageBitmap of WindowOrWorkerGlobalScope for JS takes image, which can be an img element, an SVG image element, a video element, a canvas element, a Blob object, an ImageData object, or another ImageBitmap object, and returns a promise that is resolved when a new ImageBitmap is created.

If no ImageBitmap object can be constructed, for example because the provided image data is not actually an image, then the promise is rejected instead.

If sx, sy, sw, and sh arguments are provided, the source image is cropped to the given pixels, with any pixels missing in the original replaced by transparent black. These coordinates are in the source image's pixel coordinate space, not in CSS pixels.

If options is provided, the ImageBitmap object's bitmap data is modified according to options. For example, if the premultiplyAlpha option is set to "premultiply", the bitmap data's color channels are premultiplied by its alpha channel.

Rejects the promise with an "InvalidStateError" DOMException if the source image is not in a valid state (e.g., an img element that hasn't loaded successfully, an ImageBitmap object whose [[Detached]] internal slot value is true, an ImageData object whose data attribute value's [[ViewedArrayBuffer]] internal slot is detached, or a Blob whose data cannot be interpreted as a bitmap image).

Rejects the promise with a "SecurityError" DOMException if the script is not allowed to access the image data of the source image (e.g. a video that is CORS-cross-origin, or a canvas being drawn on by a script in a worker from another origin).

Syntax

promise = self.createImageBitmap(image [, options ])
promise = self.createImageBitmap(image, sx, sy, sw, sh [, options ])

Parameters

image

An img element, an SVG image element, a video element, a canvas element, a Blob object, an ImageData object, or another ImageBitmap object.

sx

The x coordinate.

sy

The y coordinate.

sw

The width.

sh

The height.

options

Allows setting imageOrientation, premultiplyAlpha, colorSpaceConvertion, resizeWidth, resizeHeight, and resizeQuality.

imageOrientation

The image orientations: from-image and flipY.

premultiplyAlpha

The premultiply alphas: none, premultiply, and default.

colorSpaceConvertion

The color space conversions: none and default.

resizeWidth

The resize width.

resizeHeight

The resize height.

resizeQuality

The resize qualities: pixelated, low, medium, and high.

Examples

1 · image sx sy sw sh · single

2 · image sx sy sw sh · multiple

3 · options · imageOrientation · from-image

4 · options · imageOrientation · flipY

5 · options · premultiplyAlpha · none

6 · options · premultiplyAlpha · premultiply

7 · options · premultiplyAlpha · default

8 · options · colorSpaceConvertion · none

9 · options · colorSpaceConvertion · default

10 · options · resizeWidth

11 · options · resizeHeight

12 · options · resizeQuality · pixelated

13 · options · resizeQuality · low

14 · options · resizeQuality · medium

15 · options · resizeQuality · high