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.
Page Index Toggle Pages: 1
Saving Images (Read 646 times)
Saving Images
Sep 5th, 2008, 2:52pm
 
Hi,

I am trying to create an application that save out images from the main window and names the files according to the time they were saved.

This part I have working very nicely.

What I also want to do is organise where the files are saved. I want a folder to be created within the main sketch folder with that days date on it (as long as a folder does not already exist), and images created on that day to be saved into that rather than the main sketch folder (which couldvery quickly become a mess of .png's).

I also want to be able to trim the saved image down (cutting off a portion of the right hand side of it).

I'm pretty sure neither of these two things are possible in Processing at the moment but wanted to ask first in case anyone else can prove me wrong.

Cheers

Andy
Re: Saving Images
Reply #1 - Sep 5th, 2008, 3:32pm
 
to save in a folder such as "20080905", use:

saveFrame(nf(year(), 4) + nf(month(), 2) + nf(day(), 2) + "/" nf(hour(), 2), nf(minute(), 2) + ".jpg");

to get only a portion of the image, use get().

to save an image returned by get() use img.save() instead of saveFrame().
Re: Saving Images
Reply #2 - Sep 5th, 2008, 3:37pm
 
i've not tried it but i can't see a reason why the usual
saveFrame("line-####.png");

can't be replaced with
saveFrame(name);
where name is generated by you and something like "20080904/frame####.jpg"

you'll have to manage the creation of the directories yourself though using the java File class (exists(), isDirectory(), mkdir())
Re: Saving Images
Reply #3 - Sep 5th, 2008, 3:46pm
 
Thanks both of you. Both very helpful.

I'm going to have a go with the Java file class but (having zero experience with full Java) could this be something that is considered as a development within processing. Seems like it could be a very useful addition to me.

Cheers

Andy

Re: Saving Images
Reply #4 - Sep 5th, 2008, 4:14pm
 
it's already in there--you don't actually have to do any File management with exists() and the rest.. just use that line of code and it'll automatically make the folders and auto-number them as well.
Re: Saving Images
Reply #5 - Sep 5th, 2008, 6:53pm
 
Excellent cheers.

Just one question regarding Get().

The structure of it seems to suggest that it will get a portion of a named image displayed on screen.

Image.Get(X, Y, Width, Height);

I am wanting to capture various elements of the screen not just one image. Is this going to be a case of exporting a full screen image, importing it temporarily and using Get() on that? Or is there a way to use get() to capture everything displayed?

Cheers

Andy
Re: Saving Images
Reply #6 - Sep 6th, 2008, 9:33am
 
Note: it is get(), not Get(). Important in Java/Processing!
And there are two gets: the one pointed to you is get() the standalone function, which applies to the displayed image, creating a PImage object that you can save as shown.
I suppose you looked at PImage.get() instead.
Page Index Toggle Pages: 1