Getting pixel colour
Hi I'm using BufferStrategy on a fullscreen window and I would like to get the colour of a pixel I have already transferred into the BufferStrategy buffer before I do a show.
Does anyone know how I do this please? I guess I need to use getRGB, but I'm not sure on what object?
I have the BufferStrategy itself, and the Graphics2D object that I used to draw onto it, but I don't see any way to read a pixel from either of these classes.
Thanks,
Tim
[481 byte] By [
TimRyanNZ] at [2007-9-27 22:42:57]

I don't know much about this, but maybe you can use the Robot class.getPixelColor(int x, int y) http://java.sun.com/j2se/1.4.1/docs/api/java/awt/Robot.html
> I don't know much about this, but maybe you can use
> the Robot class.
> getPixelColor(int x, int y)
> http://java.sun.com/j2se/1.4.1/docs/api/java/awt/Robot.
> tml
Maybe Ceranith, but I doubt that works before show and I need to read pixels on the image while I'm building it.
I believe BufferStrategy uses a VolatileImage as the underlying buffer. Does anyone know how to get at the underlying image used by BufferStrategy? As I mentioned previously I have a Graphics2D for it - surely there is some way to read back a pixel off it? It seems such an obvious thing to want to do!
Regards,
Tim
Hi, BufferStrategy abstracts you from the actual image buffers, other wise you could call getSnapshot().
The only way that i know is to make another Image buffer then render into that, if needed use PixelGrabber to get the pixel values, then draw that buffer image on to the BufferStrategy.drawGraphics.
Harley.
> The only way that i know is to make another Image
> buffer then render into that, if needed use
> PixelGrabber to get the pixel values, then draw that
> buffer image on to the BufferStrategy.drawGraphics.
>
> Harley.
Yep thanks Harley. While I waited for a reply on the Forum that's sort of what I did. I threw away BufferStrategy completely, and now render onto a BufferedImage (which supports getRGB), and then blit that onto the displayed Frame.
I'll have a look at PixelGrabber to see if that also suits.
Thanks,
Tim