Reference get()

get()

Gets a pixel or a region of pixels from the canvas.

get() is easy to use but it's not as fast as pixels. Use pixels to read many pixel values.

The version of get() with no parameters returns the entire canvas.

The version of get() with two parameters interprets them as coordinates. It returns an array with the [R, G, B, A] values of the pixel at the given point.

The version of get() with four parameters interprets them as coordinates and dimensions. It returns a subsection of the canvas as a p5.Image object. The first two parameters are the coordinates for the upper-left corner of the subsection. The last two parameters are the width and height of the subsection.

Use p5.Image.get() to work directly with p5.Image objects.

Examples

Syntax

get(x, y, w, h)
get()
get(x, y)

Parameters

x
Number:

x-coordinate of the pixel.

y
Number:

y-coordinate of the pixel.

w
Number:

width of the subsection to be returned.

h
Number:

height of the subsection to be returned.

Notice any errors or typos? Please let us know. Please feel free to edit src/image/pixels.js and open a pull request!

Related References