| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/Window/createImageBitmap | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since September 2021.
* Some parts of this feature may have varying levels of support.
The createImageBitmap() method of the Window interface creates a bitmap from a given source, optionally cropped to contain only a portion of that source.
It accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap.
createImageBitmap(image)
createImageBitmap(image, options)
createImageBitmap(image, sx, sy, sw, sh)
createImageBitmap(image, sx, sy, sw, sh, options)
imageAn image source, which can be any one of the following:
sxThe x coordinate of the reference point of the rectangle from which the ImageBitmap will be extracted.
syThe y coordinate of the reference point of the rectangle from which the ImageBitmap will be extracted.
swThe width of the rectangle from which the ImageBitmap will be extracted.
This value can be negative.
shThe height of the rectangle from which the ImageBitmap will be extracted. This value can be negative.
options OptionalAn object that sets options for the image's extraction. The available options are:
imageOrientationSpecifies how the bitmap image should be oriented.
from-imageImage oriented according to EXIF orientation metadata, if present (default).
flipYImage oriented according to EXIF orientation metadata, if present, and then flipped vertically.
noneImage oriented according to image encoding, ignoring any metadata about the orientation (such as EXIF metadata, that might be added to an image to indicate that the camera was turned sideways to capture the image in portrait mode).
premultiplyAlphaSpecifies whether the bitmap's color channels should be premultiplied by the alpha channel.
One of none, premultiply, or default (default).
colorSpaceConversionSpecifies whether the image should be decoded using color space conversion.
Either none or default (default).
The value default indicates that implementation-specific behavior is used.
resizeWidthA long integer that indicates the output width.
resizeHeightA long integer that indicates the output height.
resizeQualitySpecifies the algorithm to be used for resizing the input to match the output dimensions.
One of pixelated, low (default), medium, or high.
A Promise which resolves to an ImageBitmap object containing bitmap data from the given rectangle.
This example loads a sprite sheet, extracts individual sprites, and then renders each sprite to the canvas. A sprite sheet is an image containing multiple smaller images, each of which you want to be able to render separately.
Original image:
<img src="50x50.jpg" />
<hr />
<canvas id="myCanvas"></canvas>
canvas {
border: 2px solid green;
}
const canvas = document.getElementById("myCanvas"),
ctx = canvas.getContext("2d"),
image = new Image();
// Wait for the sprite sheet to load
image.onload = () => {
Promise.all([
// Cut out two sprites from the sprite sheet
createImageBitmap(image, 0, 0, 32, 32),
createImageBitmap(image, 32, 0, 32, 32),
createImageBitmap(image, 0, 0, 50, 50, { imageOrientation: "flipY" }),
]).then((sprites) => {
// Draw each sprite onto the canvas
ctx.drawImage(sprites[0], 0, 0);
ctx.drawImage(sprites[1], 32, 32);
ctx.drawImage(sprites[2], 64, 64);
});
};
// Load the sprite sheet from an image file
image.src = "50x50.jpg";
| Specification |
|---|
| HTML # dom-createimagebitmap-dev |
This page was last modified on Jun 23, 2025 by MDN contributors.
WindowcachesclosedcookieStorecrashReportcredentiallesscrossOriginIsolatedcryptocustomElementsdevicePixelRatiodocumentdocumentPictureInPictureeventexternalfenceframeElementframesfullScreenhistoryindexedDBinnerHeightinnerWidthisSecureContextlaunchQueuelengthlocalStoragelocationlocationbarmenubarmozInnerScreenXmozInnerScreenYnamenavigationnavigatoropenerorientationoriginoriginAgentClusterouterHeightouterWidthparentperformancepersonalbarschedulerscreenscreenLeftscreenTopscreenXscreenYscrollbarsscrollMaxXscrollMaxYscrollXscrollYselfsessionStoragesharedStoragespeechSynthesisstatusstatusbartoolbartoptrustedTypesviewportvisualViewportwindowalert()atob()blur()btoa()cancelAnimationFrame()cancelIdleCallback()captureEvents()clearImmediate()clearInterval()clearTimeout()close()confirm()createImageBitmap()dump()fetch()fetchLater()find()focus()getComputedStyle()getDefaultComputedStyle()getScreenDetails()getSelection()matchMedia()moveBy()moveTo()open()postMessage()print()prompt()queryLocalFonts()queueMicrotask()releaseEvents()reportError()requestAnimationFrame()requestFileSystem()requestIdleCallback()requestResize()resizeBy()resizeTo()scroll()scrollBy()scrollByLines()scrollByPages()scrollTo()setImmediate()setInterval()setResizable()setTimeout()showDirectoryPicker()showOpenFilePicker()showSaveFilePicker()sizeToContent()stop()structuredClone()webkitConvertPointFromNodeToPage()webkitConvertPointFromPageToNode()afterprintappinstalledbeforeinstallpromptbeforeprintbeforeunloadblurdevicemotiondeviceorientationdeviceorientationabsoluteerrorfocusgamepadconnectedgamepaddisconnectedhashchangelanguagechangeloadmessagemessageerrorofflineonlineorientationchangepagehidepagerevealpageshowpageswappopstaterejectionhandledresizescrollsnapchangescrollsnapchangingstorageunhandledrejectionunloadvrdisplayactivatevrdisplayconnectvrdisplaydeactivatevrdisplaydisconnectvrdisplaypresentchangeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |