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 & HelpSyntax Questions › saving a screenshot to a PImage
Page Index Toggle Pages: 1
saving a screenshot to a PImage (Read 1178 times)
saving a screenshot to a PImage
Jan 9th, 2007, 3:51pm
 
I'm trying save a screenshot of my game to a PImage so I can use it as a background image after a state change. The code I'm using is being executed at the beginning of the draw loop, before anything has been drawn but also before any calls to background(), which I assume means that the pixel buffer still has stuff in it. Am I wrong? Here's the code (back is a PImage, the declaration is elsewhere):

Code:

back = createImage(width, height, ARGB);
loadPixels();
arraycopy(pixels, back.pixels);
Re: saving a screenshot to a PImage
Reply #1 - Jan 9th, 2007, 4:16pm
 
createGraphics doesn't create a PImage.

Try this:
Code:

PImage back;
void setup(){
size(400, 400);
back = new PImage(400, 400, ARGB);
rect(0,0,width, height);
loadPixels();
back.copy(g,0,0,width,height,0,0,width,height);
background(0);
}
void draw(){
image(back, 0, 0);
rect(mouseX, mouseY, 50, 50);
if(mousePressed){
loadPixels();
back.copy(g,0,0,width,height,0,0,width,height);
back.updatePixels();
}
}

(Going to post a bug about 'g', I shouldn't have to reference it but I can't get this code to work without it.)
(Edit: Oh, I already have)
Re: saving a screenshot to a PImage
Reply #2 - Jan 9th, 2007, 7:52pm
 
this should be all you need:

PImage saved = get();
Re: saving a screenshot to a PImage
Reply #3 - Jan 9th, 2007, 10:55pm
 
back = get(); does the trick.

What doesn't work is:

background(back);

I had to change that line to:

image(back, 0, 0);

as in steed's example. The doc for background() claims you can use an image as an argument, is this some kind of weird special case bug?
Re: saving a screenshot to a PImage
Reply #4 - Jan 10th, 2007, 12:13am
 
that might be a special case bug. try changing the renderer to P3D instead of JAVA2D (if that's what you're using) and see if the image shows up.
Re: saving a screenshot to a PImage
Reply #5 - Jan 10th, 2007, 12:29am
 
Oh, right, forgot to mention, I did try that.

background(back); works with P3D and JAVA2D.

It does not work with OPENGL, which is the mode I'm running in.
Re: saving a screenshot to a PImage
Reply #6 - Jan 10th, 2007, 3:31pm
 
gotcha, that's this bug:
http://dev.processing.org/bugs/show_bug.cgi?id=91
Page Index Toggle Pages: 1