• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Points on an Image

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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.
 
Ed Ewing
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this:



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