Skip to content
Related Articles

Related Articles

Improve Article

HTML | canvas ImageData data Property

  • Last Updated : 14 Apr, 2021
Geek Week

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: 

  • R denotes the red color (0-255)
  • G denotes the green color( 0-255)
  • B denotes the blue color(0-255)
  • A denotes the alpha channel (0-255; 0 is fully transparent and 255 is fully visible)

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



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


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

  • Chrome
  • Internet Explorer 9.0
  • Safari
  • Firefox
  • Opera


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :