• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hit detection by color

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic