The Wayback Machine - https://web.archive.org/web/20150905063442/https://developer.mozilla.org/en-US/docs/Web/API/CreateImageBitmap

CreateImageBitmap

by 2 contributors:

This article is in need of a technical review.

The createImageBitmap method accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.

Syntax

createBitmapImage(image).then(function(response) { ... });
createBitmapImage(image, sx, sy, sw, sh).then(function(response) { ... });

Parameters

image
An image source, which can be an <img>, <video>, or <canvas> element, a Blob, ImageData or CanvasRenderingContext2D object, or another ImageBitmap object.
sx
The x coordinate of the reference point of the rectangle from which the ImageBitmap will be extracted.
sy
The y coordinate of the reference point of the rectangle from which the ImageBitmap will be extracted.
sw
The width of the rectangle from which the ImageBitmap will be extracted. This value can be negative.
sh
The height of the rectangle from which the ImageBitmap will be extracted. This value can be negative.

Return value

A Promise which resolves to an ImageBitmap object containing bitmap data from the given rectangle.

Example

var canvas = document.getElementById('mycanvas'),
ctx = canvas.getContext('2d'),
image = new Image();

image.onload = function () {
	Promise.all([
		createImageBitmap(this, 0, 0, 32, 32),
		createImageBitmap(this, 32, 0, 32, 32)
	]).then(sprites)
	{
		ctx.drawImage(sprites[0], 0, 0);
		ctx.drawImage(sprites[1], 32, 32);
	});
}

image.src = 'sprites.png';

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'createImageBitmap' in that specification.
Living Standard  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? ? ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? [1] ? ? ?

See also

Document Tags and Contributors

Contributors to this page: Kaku, adria
Last updated by: Kaku,