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 › Save current screen to PGraphics container
Page Index Toggle Pages: 1
Save current screen to PGraphics container (Read 494 times)
Save current screen to PGraphics container
Jul 7th, 2009, 8:48am
 
Hi,

I am creating a paint program and was trying to implement an UNDO feature.

I tried saving the current image to a file and reloading but the save and load to JPG takes too long, up to 5 seconds, and makes the program unusable.

I was wondering if I could use a PGraphics variable:-



But, instead of using undo.line, I would somehow grab the current image?

Anyone got any ideas or suggestions please? :)
Re: Save current screen to PGraphics container
Reply #1 - Jul 7th, 2009, 8:59am
 
I'd guess you might want to just copy data from the pixels[] array (also see loadPixels()).

I'd guess the most efficient approach would be to record only the previous values of pixels that are changed during a given action, perhaps using an ArrayList...  You should then be able to set() them back when undo is called.

I suspect grabbing the whole image each time a change is made may prove slow - though that will no doubt depend on the canvas size.
Re: Save current screen to PGraphics container
Reply #2 - Jul 7th, 2009, 9:02am
 
Woah, the forum is not responsive today, multiple posts galore! Hint: go to each extra message and delete it from there.

Look at get() to capture the current sketch display to a PImage.
Page Index Toggle Pages: 1