HTML Canvas ImageData data
Property
Example
Create a 100*100 pixel ImageData object where each pixel is set to red:
Canvas
JavaScript:
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the ImageData data
property.
Note: Internet Explorer 8 and earlier versions do not support the <canvas> element.
Definition and Usage
The data
property returns an object containing the image data of the specified ImageData object.
For each pixel in the ImageData object, there are four pieces of information, namely the RGBA values:
R - Red (0-255)
The color/alpha information is stored as an array in the data
property of the ImageData object.
Example:
Syntax to change the first pixel in the ImageData object to red:
Syntax to change the second pixel in the ImageData object to green:
Tip: See the createImageData(), getImageData(), and putImageData() methods for more information about the ImageData object.
JavaScript Syntax
| JavaScript Syntax: | imageData.data; | | --- | --- |