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]
# 1
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
Ceranith at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 2

> 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

TimRyanNZ at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 3

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.

harleyrana at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 4
I didn't read the whole thing, sorry. What harley said sounds good :)
Ceranith at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 5
why exactly do you need to read pixel values?
Abuse at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 6
> why exactly do you need to read pixel values?Player movement control mainly.
TimRyanNZ at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...
# 7

> 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

TimRyanNZ at 2007-7-7 13:38:47 > top of Java-index,Other Topics,Java Game Development...