wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Hit detection by color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hit detection by color" Watch "Hit detection by color" New topic
Author

Hit detection by color

Jamie Brandon
Greenhorn

Joined: Aug 01, 2004
Posts: 2
This is for a simple point and click game. Because of the nature of the game I would prefer to use the swing UI rather than using basic graphics (it would take too long to explain why). At the moment Im using labels with gif icons and transparent backgrounds. Is there any way to find the color displayed at the point where the mouse clicked? I realise that the color model holds data for each pixel but i dont know how the coordinates map to the pixel number and the RGB at each pixel just seems to be counting upwards in any case. Also, Id be grateful if someone could explain how the gif transparancies work and what RGB value is registered for a transparent background.

Thanks, Jamie
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The PixelGrabber api has an example that shows how to access the ColorModel int[].

This example works in older j2se versions. If you are using j2se 1.4+ you can load your image(s) with ImageIO.read which returns a BufferedImage. In the BufferedImage api you can then use the method getRGB to get your color information.

The PixelGrabber uses a default RGB ColorModel (see PixelGrabber constructor detail). More information is available in the DirectColorModel api.
Jamie Brandon
Greenhorn

Joined: Aug 01, 2004
Posts: 2
Thanks.

If a bufferd image would be so easy to use, is there any way to access the biffer used in the swing display or would I have to buffer it myself to do it that way?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hit detection by color
 
Similar Threads
BufferedImage and scanning pixels
Pixel Transparency
Searching a Vector for most common numbers
Drawing Canvas
changing gray pixels....