How can I determine the color of a pixel displayed in a GUI?

Andre van Dalen

If you use double buffering, your question comes down to how to determine the pixel color in the image you use to paint to the screen. You can use the PixelGrabber class to tranform (part of) your Image into an int[] and read the pixel color from that.

If you want to determine the color of a pixel on the screen, you need to use JNI to call a C++ routine that retrieves pixels from the screen.

[FAQ Manager note: Double Buffering refers to drawing to an alternate, offscreen image before dumping that image to the screen.]