Name

CRC.getImageData() — gets individual pixels from a canvas

Synopsis

ImageData getImageData(x, y, w, h)

Arguments

x, y

The coordinates of one corner (usually the upper-left) of the rectangular region of pixels to be returned. These arguments are not transformed by the current transformation matrix.

w, h

The width and height of the rectangle of pixels to be returned. These arguments are not transformed by the current transformation matrix. These arguments are usually positive, but negative values are allowed.

Returns

A newly-created ImageData object that contains the pixel values for all pixels within the rectangle.

Description

The arguments to this method are untransformed coordinates that specify a rectangular region of the canvas. The method copies the pixel data from that region of the canvas into a new ImageData object and returns that object. See ImageData for an explanation of how to access the red, green, blue, and alpha components of the individual pixels.

The RGB color components of the returned pixels are not premultiplied by the alpha value. If any portions of the requested rectangle lie outside the bounds of the canvas, the associated pixels in the ImageData are set to transparent black (all zeros). If the implementation uses more than one device pixel per CSS pixel then the width and height properties of the returned ImageData object will be different than the w and h arguments.

Like Canvas.toDataURL(), this method is subject to a security check to prevent cross-origin information ...

Get Canvas Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.