• 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

Points on an Image

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supposing I have drawn a picture in a frame with paintComponent
method, and then saved this as an Image. Then suppose I chose the point
(100,100) on the image, is it possible to determine the colour of this
point??

Basically, I am constructing a breakout game. I have it working, but
there are too many if statements to go through to check if the ball has
hit the bricks, and in which way. If I could test the colour of some points around the edge of the ball, I could determine if it was about to hit a brick or not.

Any help is appreciated, thanks
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh, I just read a post below, someone amazingly had the same problem.
I need to use the getRGB() method on a BufferedImage object. Just checking
the API now.
Any hints/tips are welcomed. Thanks
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I've got it working kind of.
I'm using a BufferedImage object declared by:

Now, when I use getRBG(x,y) over part of the image that is green, it returns -16711936
For blue, it returns -16776961
For black, it returns -16777216 (=-256*256*256)
For white, it returns -1

Usually when I create a Color using new Color(r,b,g)
I find that (0,0,0) is black, (255,255,255) is white and so on..
Can anyone explain the link between these different values.
Thanks
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the PixelGrabber api, first block of code in the discussion section. The 'int' returned by 'getRGB' is the 'pixel' variable in that block.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like this:



Or you can create a new Color object:
 
reply
    Bookmark Topic Watch Topic
  • New Topic