Open In App

HTML | canvas ImageData data Property

The ImageData data property is used to return an object that contains image data of the specified ImageData object. 
Every pixel in an ImageData object contains four pieces of information i.e. the RGBA values: 
 

An array which is stored in the data property of the ImageData object stores the information of the color/alpha.
Syntax: 
 



imageData.data;

Example: 
 




<!DOCTYPE html>
<html>
 
<body>
    <h3 style="color:green">
      GeeksforGeeks
  </h3>
    <h3>HTML canvas ImageData data property</h3>
    <canvas id="myCanvas"
            width="200"
            height="200"
            style="border:2px solid ;">
  </canvas>
    <p id=g eeks></p>
 
    <script>
        var can = document.getElementById("myCanvas");
        var gfg = can.getContext("2d");
        var imgData = gfg.createImageData(150, 100);
 
        var i;
        for (i = 0; i < imgData.data.length; i += 3) {
            imgData.data[i + 0] = 100;
            imgData.data[i + 1] = 0;
            imgData.data[i + 2] = 0;
        }
 
        gfg.putImageData(imgData, 10, 10);
    </script>
 
</body>
 
</html>

Output: 
 



Browsers supported: The browsers supported by HTML canvas ImageData data Property are listed below: 
 

 

Article Tags :