get()

Image / Pixels

Description

Reads the color of any pixel or grabs a section of a PImage.

Syntax

color get(int x, int y)

Parameters

NameTypeDescription
xintx-coordinate
yinty-coordinate

Returns

color

Related

Under the Hood

From Processing.h:

unsigned int get(int x, int y) const { if (x<0||x>=width||y<0||y>=height) return 0; return pixels[y*width+x]; } PImage get(int x, int y, int w, int h) const { PImage out(w, h); for (int iy=0; iy<h; iy++) for (int ix=0; ix<w; ix++) out.pixels[iy*w+ix] = get(x+ix, y+iy); return out; } int get(int i) const { return data[i]; } float get(int i) const { return data[i]; } std::string get(int i) const { return data[i]; } T get(int i) const{ return data[i]; } T* get(int i) const{ return data[i]; } V& get(const K& k) { return _data[k]; } int get(const std::string& k, int def=0) const { auto it=data.find(k); return it!=data.end()?it->second:def; } float get(const std::string& k, float def=0) const { auto it=data.find(k); return it!=data.end()?it->second:def; } std::string get(const std::string& k, const std::string& def="") const { auto it=data.find(k); return it!=data.end()?it->second:def; } V& get(const K& k) { return data[k]; } color get(int x, int y);

Under the Hood

From Processing.cpp:

color PApplet::get(int x, int y) { unsigned char p[4]; glReadPixels(x, winHeight - 1 - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, p); return colorVal(p[0], p[1], p[2], p[3]); }