- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Class | PImage
Name | ### get()
Examples |
    PImage mountains = loadImage("rockies.jpg");
    background(mountains);
    noStroke();
    color c = mountains.get(60, 90);
    fill(c);
    rect(25, 25, 50, 50);
    PImage mountains = loadImage("rockies.jpg");
    background(mountains);
    PImage newMountains = mountains.get(50, 0, 50, 100);
    image(newMountains, 0, 0);
Description | Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a section of the display window by specifying an additional width and height parameter. When getting an image, the x and y parameters define the coordinates for the upper-left corner of the image, regardless of the current imageMode(). If the pixel requested is outside of the image window, black is returned. The numbers returned are scaled according to the current color ranges, but only RGB values are returned by this function. For example, even though you may have drawn a shape with colorMode(HSB), the numbers returned will be in RGB format. Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to get(x, y) using pixels[] is pixels[y*width+x]. See the reference for pixels[] for more information.
Syntax |
    pimg.get(x, y)
    pimg.get(x, y, w, h)
    pimg.get()
Parameters |
pimg | PImage: any object of type PImage
x | int: x-coordinate of the pixel
y | int: y-coordinate of the pixel
w | int: width of pixel rectangle to get
h | int: height of pixel rectangle to get
Returns | int or PImage
Related | set() pixels[] copy()

Updated on January 1, 2021 03:38:09am EST
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.