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 sections of the screen.
Page Index Toggle Pages: 1
Saving sections of the screen. (Read 642 times)
Saving sections of the screen.
Nov 15th, 2009, 10:40am
 
I've been looking through get(), copy(), saveFrame etc to find a way of saving the current screen of the sketch, and until now saveFrame worked ok, but i now only want to save an area of the screen to be saved to the data file. Is there a function that 'combines' saveFrame & copy()!?
Cheers, W.
Re: Saving sections of the screen.
Reply #1 - Nov 15th, 2009, 10:52am
 
I'm pretty sure you can use createImage() for that...
Re: Saving sections of the screen.
Reply #2 - Nov 15th, 2009, 10:57am
 
OK i'll just giv it another go:)
Re: Saving sections of the screen.
Reply #3 - Nov 15th, 2009, 11:58am
 
Sorry - I'd assumed you'd looked at PImage docs and I should have looked at them more carefully  Embarrassed

Since get() returns a PImage you can simply use PImage.save() to save to a file.  Also note that you can use get() on its own - without attaching it to a PImage object - to get a portion of the sketch window...

So you can do the following:

Code:
int divisions = 10;

void setup() {
 size(400,400);
 int divWidth = width/divisions;
 int divHeight = height/divisions;
 
 for(int i=0; i<width; i+=divWidth) {
   for(int j=0; j<height; j+=divHeight) {
     int r = (int)random(255);
     int g = (int)random(255);
     int b = (int)random(255);
     fill(r,g,b);
     rect(i,j,divWidth,divHeight);
   }
 }
 // Create a PImage from any portion of the screen:
 PImage outputImage = get(100,100,200,200);
 // And save it...
 outputImage.save("img.jpg");
}
Re: Saving sections of the screen.
Reply #4 - Nov 15th, 2009, 12:31pm
 
Stunning that's a (horribly obvious solution after so long thinking about it! &) massive help, thanks once again!
Page Index Toggle Pages: 1