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 › Is it possible to only save certain areas
Page Index Toggle Pages: 1
Is it possible to only save certain areas? (Read 380 times)
Is it possible to only save certain areas?
Jun 19th, 2008, 2:31pm
 
I'm mucking around with the facial detection libraries and thought is would be cool to write the faces out to a file using save() or the like for processing images made up from thousands of little faces.

Code:
 void drawFace() {
int [][] res = face.getFaces();
if (res.length>0) {
for (int i=0;i<res.length;i++) {
int x = res[i][0];
int y = res[i][1];
int w = res[i][2];
int h = res[i][3];
rect(x,y,w,h);


I'm not having much luck at the moment, is it possible?

The above code draws a rectangle around the faces nicely but I can't seem to get it to write just those areas out to files.

Thanks for your suggestions!
Re: Is it possible to only save certain areas?
Reply #1 - Jun 19th, 2008, 2:57pm
 
You can create a PImage and copy the portion of screen there, then save it.
PImage subImage = createImage(subWidth, subHeight, RGB);
subImage.copy(bigImage, posX, posY, subWidth, subHeight, 0, 0, subWidth, subHeight);
subImage.save("one face.jpg");
Re: Is it possible to only save certain areas?
Reply #2 - Jun 19th, 2008, 3:10pm
 
Thanks so much.  That's a good suggestion.

I just implemented it and it works great.
Re: Is it possible to only save certain areas?
Reply #3 - Jun 19th, 2008, 5:45pm
 
it's simpler than that:

Code:
PImage sub = get(x, y, w, h);
sub.save("one.jpg");
Re: Is it possible to only save certain areas?
Reply #4 - Jun 19th, 2008, 6:59pm
 
Cool!
It shows:
1) There are more than one way to skin a cat...
2) Processing is full of nice shortcuts, one just have to read the doc and remember it! Wink
Page Index Toggle Pages: 1