is there any fast&easy way to store the image, which is already drawn to Graphics2D context in an image.
(pseudo) BufferedImage img = g2D.getImage() … ?
is there any fast&easy way to store the image, which is already drawn to Graphics2D context in an image.
(pseudo) BufferedImage img = g2D.getImage() … ?
No. because in theory a graphics context is only used for write operations… (ignoring the read-modify-write required of some anti-aliasing or compositing operations).
Only if the context is attached to a readable image (e.g. BufferedImage) can you get the image out… and still not through the graphics context.
although if you wanted to, you could write your own implementation of Composite, which, via a read-modify-write, grabbed the destination images pixels and wrote them to somewhere else 
its abit of a hack, but I’ve done it - and it does work 
(although, you need security privileges to be able to use a Composite other than Suns AlphaComposite implementation - so it won’t work in unsigned Applets.)
then you perhaps know a better workaround for my problem.
imagine the following:
my game ends and a little winner-screen with animations appears. but the display not only changes, the playfield fades out up to a point where you can still see it, but much darker, so that the new animations are a clear contrast to the background.
for realizing the fade effect i do nothing more than painting a black rectangle with translucent color-option over the gamefield, then i paint the animations.
problem: i cannot refresh the whole picture to clear the last animation-sequences because i have no image of the old graphic-context. consequence: all frames are painted over and over to the screen…
What do you use to draw your gamefield normally?
Why can’t you draw it into a buffered image just before this sequence?
hmmm, i think i didnt get your question properly.
i think i explain in short how it works:
main program stores one of the game-states (an object representing the game, the menu, the highscore whatever)
in an interface called metaGame.
so if the game ends, the gameField - object calls the main-class for changing :
metaGame = new HighScore(...)
in my applet’s paint(…) method theres only one important entyr:
metaGame.update(g2D);
so that the actual gameState object is painted.
when metaGame is set to highScore and shall paint first time it gets the graphics context g2D with the last picture taken at the gamefield. but i have no way to get this picture again within the highScore. so if i fade out and draw something to the graphics context i have not the clear gameField picture for next frame.
so i thought it would be possible to store the gameField picture in an image and paint it every frame as background.
[quote]when metaGame is set to highScore and shall paint first time it gets the graphics context g2D with the last picture taken at the gamefield. but i have no way to get this picture again within the highScore.
[/quote]
Ah! Well that is the real problem. Your design is limiting you. There should be a way to draw the gamefield when the game is over. Then you could just pass the graphics context of a BufferedImage.
I think the real problem lies in how you have designed the rendering framework. You should probably think about it for a while to see if there is an easy way to re-draw the last game state to a BufferedImage after you have determined the game is over.