Canvas

Canvas Tutorials

Canvas Methods and Properties

HTML canvas getImageData() Method

HTML canvas getImageData() Method

 

 

The getImageData() method is used to return an ImageData object that copies the pixel data for the specified rectangle on a canvas.
Every pixel in the ImageData object has four pieces of information. These are:-

  1. R - The color red (from 0-255)
  2. G - The color green (from 0-255)
  3. B - The color blue (from 0-255)
  4. A - The alpha channel (from 0-255; 0 is transparent and 255 is fully visible)

The color information is held in an array and is stored in the data property of the ImageData object.

 

Syntax:-

 

Its syntax is- context.getImageData(x, y, width, height);

 

Further Explanation:-

 

Parameter Description
x The x-coordinate of the upper-left corner to start copying from
y The y-coordinate of the upper-left corner to start copying from
width The width of the rectangular area you will copy
height The height of the rectangular area you will copy

Code Explanation

All Tutorials related to Canvas Methods and Properties

All Sections related to Canvas