Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting the image out of a Graphics context  (Read 1461 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Devvie




Java games rock!


« Posted 2004-03-21 13:24:58 »

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() ...   ?
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #1 - Posted 2004-03-21 15:27:47 »

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.

Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #2 - Posted 2004-03-21 16:12:41 »

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 Smiley

(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.)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Serethos

Junior Devvie




Java games rock!


« Reply #3 - Posted 2004-03-21 18:22:45 »

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...
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #4 - Posted 2004-03-21 20:13:03 »

What do you use to draw your gamefield normally?

Why can't you draw it into a buffered image just before this sequence?

Offline Serethos

Junior Devvie




Java games rock!


« Reply #5 - Posted 2004-03-22 09:30:00 »

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 :

1  
 metaGame = new HighScore(...) 


in my applet's paint(...) method theres only one important entyr:

1  
 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.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #6 - Posted 2004-03-22 14:09:08 »

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.


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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (12 views)
2014-11-28 16:25:35

PocketCrafter7 (7 views)
2014-11-28 16:25:09

PocketCrafter7 (8 views)
2014-11-28 16:24:29

toopeicgaming1999 (75 views)
2014-11-26 15:22:04

toopeicgaming1999 (65 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!