The ImageData interface represents the underlying pixel data of an area of a <canvas> element. It is created using the ImageData() constructor or creator methods on the CanvasRenderingContext2D object associated with a canvas: createImageData() and getImageData(). It can also be used to set a part of the canvas by using putImageData().
Constructors
ImageData()- Creates an
ImageDataobject from a givenUint8ClampedArrayand the size of the image it contains. If no array is given, it creates an image of a black rectangle. Note that this is the most common way to create such an object in workers ascreateImageData()is not available there.
Properties
ImageData.dataRead only- Is a
Uint8ClampedArrayrepresenting a one-dimensional array containing the data in the RGBA order, with integer values between0and255(included). ImageData.heightRead only- Is an
unsignedlongrepresenting the actual height, in pixels, of theImageData. ImageData.widthRead only- Is an
unsignedlongrepresenting the actual width, in pixels, of theImageData.
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'ImageData' in that specification. |
Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 4 | Yes | 14 | 9 | 9 | 3.1 |
| Support in workers | Yes | ? | 25 | ? | ? | ? |
ImageData() constructor | 42 | Yes | 29 | No | 29 | ? |
data | Yes | Yes | 14 | 9 | 9 | 3.1 |
height | Yes | Yes | 14 | 9 | 9 | 3.1 |
width | Yes | Yes | 14 | 9 | 9 | 3.1 |
| Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
|---|---|---|---|---|---|---|---|
| Basic support | Yes | Yes | ? | 14 | 10 | 3.2 | ? |
| Support in workers | Yes | ? | ? | 25 | ? | ? | ? |
ImageData() constructor | No | 42 | ? | 29 | ? | ? | ? |
data | ? | Yes | Yes | 14 | Yes | Yes | ? |
height | Yes | Yes | Yes | 14 | Yes | Yes | ? |
width | Yes | Yes | Yes | 14 | Yes | Yes | ? |
See also
CanvasRenderingContext2D- The
<canvas>element and its associated interface,HTMLCanvasElement.