Reference get()

get()

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

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

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

The version of img.get() with two parameters, as in img.get(10, 20), 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 img.get() with four parameters, as in img,get(10, 20, 50, 90), interprets them as coordinates and dimensions. The first two parameters are the coordinates of the upper-left corner of the subsection. The last two parameters are the width and height of the subsection. It returns a subsection of the canvas in a new p5.Image object.

Use img.get() instead of get() to work directly with images.

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.

Returns

p5.Image: subsection as a p5.Image object.
Notice any errors or typos? Please let us know. Please feel free to edit src/image/p5.Image.js and open a pull request!

Related References