HTML canvas createImageData() Method

❮ HTML canvas Reference


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

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

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


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

Standard Syntax

JavaScript syntax:

var imgData=context.createImageData(imageData);

Browser Support


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