It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Points on an Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Points on an Image" Watch "Points on an Image" New topic

Points on an Image

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
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

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

Joined: Apr 11, 2005
Posts: 750
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

Joined: Apr 11, 2005
Posts: 750
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.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Check the PixelGrabber api, first block of code in the discussion section. The 'int' returned by 'getRGB' is the 'pixel' variable in that block.
Ed Ewing

Joined: Aug 30, 2005
Posts: 29
Try something like this:

Or you can create a new Color object:
I agree. Here's the link:
subject: Points on an Image
It's not a secret anymore!