This site requires JavaScript, please enable it in your browser!
Greenfoot back
danpost
danpost wrote ...

2011/6/21

On Saving the Image of the World

danpost danpost

2011/6/21

#
Is there a way to, basically, take a snap-shot of the world? i.e. save a copy of the image displayed at any moment?
DonaldDuck DonaldDuck

2011/6/21

#
You can get the worlds image by calling getBackground() from the world subclass. Introduce a variable (say GreenfootImage world_image) and assign it with world_image = getBackground();
danpost danpost

2011/6/21

#
Maybe I was not specific enough (I thought I was). I was not asking about the BACKground image; I wanted to know about the FOREground image!
davmac davmac

2011/6/21

#
I think the short answer is "no". The long answer is that you can get the background image of the world, duplicate it (by painting it into a new image), and then manually paint all the objects in the world at the correct position and rotation. It's not simple to do and you may not be able to guarantee that you paint the objects in the same order as Greenfoot does.
danpost danpost

2011/6/21

#
Can I, then, copy and save that image to a ".png" file?
davmac davmac

2011/6/22

#
Certainly. You can get a BufferedImage instance from a GreenfootImage by calling the getAwtImage() method and then you can use the standard Java API to write that to a file. For this, Google is your friend. Here's a couple of links - one, two .
danpost danpost

2011/6/22

#
Thanks davmac; I appreciate your input. May God shower you with blessings!!
You need to login to post a reply.