HTML canvas createImageData() Method

❮ HTML canvas Reference

Example

let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");

let imgData = ctx.createImageData(100, 100);
let i;

for (i = 0; i < imgData.data.length; i += 4) {
  imgData.data[i+0] = 255;
  imgData.data[i+1] = 0;
  imgData.data[i+2] = 0;
  imgData.data[i+3] = 255;
}
ctx.putImageData(imgData, 25, 25);

Meaning

The createImageData() method creates a new, blank ImageData object.


Standard Syntax

JavaScript syntax:

var imgData=context.createImageData(imageData);



Browser Support




Status







Parameter Values

Parameter Description
width Specifies the width of the new ImageData object, in pixels.
height Specifies the height of the new ImageData object, in pixels.
imageData Specifies the anotherImageData object
❮ HTML canvas Reference