• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting pixels from a Graphics instance

 
Neville Campbell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to read pixel data from a Graphics instance?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Neville Campbell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic