Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Getting pixels from a  Graphics instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting pixels from a  Graphics instance" Watch "Getting pixels from a  Graphics instance" New topic
Author

Getting pixels from a Graphics instance

Neville Campbell
Greenhorn

Joined: Mar 31, 2001
Posts: 6
Is there any way to read pixel data from a Graphics instance?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

No... you use Graphics to draw to components... you can't query the Graphics object to see what was drawn... though you can create an Image (like BufferedImage), draw to that, and ask the image what is drawn on it...

What exactly are you trying to do?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Neville Campbell
Greenhorn

Joined: Mar 31, 2001
Posts: 6
My question is motivated by animation in full-screen exclusive mode, typically with page flipping. If an animation involves relatively few scene changes between frames, I might render the pages incrementally. Each page would receive only the necessary updates before being displayed.
Now consider the implementation of a sprite under these circumstances. Just before a sprite is rendered, it would be useful to have the sprite save the portion of the scene it is about to cover. The sprite would store a sprite-sized overwritten image for each page. The appropriate image would be restored to the volatile buffer immediately after each invocation of bufferStrategy.getDrawGraphics().
Unfortunately I know of no way to retrieve the portion of the image that is about to be overwritten by the sprite. I don't know how to access the underlying VolatileImage.
Any suggestions? Or am I out of luck?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting pixels from a Graphics instance