HTML | canvas createImageData() Method

The createImageData() method is used to create a new blank ImageData object. The pixels of the new object is transparent black by default.

There are two syntaxes of the createImageData() method:

  • It is used to create a new ImageData object with the specified dimensions(in pixels):

    var imgData = context.createImageData(width, height);
  • It is used to create a new ImageData object with the same dimensions as the object specified by anotherImageData. It doesn’t copy the image data.

    var imgData=context.createImageData(imageData);

Parameter Values:

  • width: It denotes the width(in pixels) of the new ImageData object.
  • height: It denotes the height(in pixels) of the new ImageData object.
  • imageData: It is the anotherImageData object






<!DOCTYPE html>
    <h3 style="color:green">GeeksforGeeks</h3>
    <h3>HTML canvas createImageData() Method</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);



Supported Browsers:

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.