FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
      Language \ Environment \ Libraries \ Comparison
 
   
   
Abridged (A-Z) \ Complete (A-Z)  
   
  Reference for Processing (BETA) version 91+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.  
Name  

get()

   
Examples  
PImage myImage = loadImage("topanga.jpg"); 
image(myImage, 0, 0); 
PImage cp = get(); 
image(cp, 50, 0); 
 
PImage myImage = loadImage("topanga.jpg"); 
image(myImage, 0, 0); 
color cp = get(30, 20); 
fill(cp); 
rect(30, 20, 55, 55); 
Description   Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Get the value of one pixel by specifying an x,y coordinate. Get a section of the display window by specifing an additional width and height parameter. 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.

The imageMode() function changes the way the parameters work. For example, a call to imageMode(CORNERS) will change the width and height parameters to define the x and y values of the opposite corner of the image.

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]". The (BETA) version of Processing requires calling loadPixels() to load the display window data into the pixels[] array before getting the values.
   
Syntax  
get()
get(x, y)
get(x, y, width, height)
   
Parameters  
x   int: x-coordinate of the pixel

y   int: y-coordinate of the pixel

width   int: width of pixel rectangle to get

height   int: height of pixel rectangle to get

   
Returns   color or PImage
   
Usage   Web & Application
   
Related   set()
pixels[]
 
 






   
 
Updated: Fri Jul 15 16:35:40 PDT 2005
 
 








Creative Commons License
 
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info