This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.
The ImageData()
constructor returns a newly instantiated ImageData
object build from the typed array given and having the specified width and height.
This constructor is the preferred way of creating such an object in a worker.
Syntax
new ImageData(array, width, height); new ImageData(width, height);
Parameters
array
- A
Uint8ClampedArray
containing the underlying pixel representation of the image. If no such array is given, an image with a black rectangle of the given dimension will be created. width
- An unsigned long representing the width of the represented image.
height
- An unsigned long representing the height of the represented image. This value is optional if an array is given: it will be inferred from its size and the given width.
Example
var imageData = new ImageData(100, 100); // Creates a 100x100 black rectangle // ImageData { width: 100, height: 100, data: Uint8ClampedArray[40000] }
Specification
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'ImageData()' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 42 | 29.0 (29.0) | Not supported | 30 | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | 29.0 (29.0) | Not supported | ? | ? | 42 |
See also
CanvasRenderingContext2D.createImageData()
, the creator method that can be used outside workers.