We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Getting Java Image object of the current sketch
Page Index Toggle Pages: 1
Getting Java Image object of the current sketch (Read 1020 times)
Getting Java Image object of the current sketch
Mar 30th, 2010, 12:55am
 
I used to have some experience in Java, and when we want to draw something in Java, we create an Image, get graphical context and draw it from there.

What about in Processing? I need to get a reference to the image we are drawing. Is it possible to get the Image object in Processing?
Re: Getting Java Image object of the current sketch
Reply #1 - Mar 30th, 2010, 1:23am
 
g.get() gets the image from the current drawing surface. In the following example, I draw something to the left half of the screen, grab an image of it, and then draw it on the right half of the screen.

Quote:
PImage img;
void setup(){
size(400,200);
img = createImage(400,200,RGB);
noStroke();
}
void draw(){
  fill(255,0,0);
  rect(0,0,200,200);
  fill(0,255,0);
  rect(20,30,40,50);  
  img = g.get();
  image(img, 200, 0);
}

Re: Getting Java Image object of the current sketch
Reply #2 - Mar 30th, 2010, 2:05am
 
g.get() gives you PImage, but I need Image.
Re: Getting Java Image object of the current sketch
Reply #3 - Mar 30th, 2010, 2:39am
 
Have you checked http://dev.processing.org/reference/core/javadoc/processing/core/PImage.html

You can invoke getImage() on a PImage to get a BufferedImage.
Page Index Toggle Pages: 1