File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Game Development and the fly likes Determining Pixel Colour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Determining Pixel Colour" Watch "Determining Pixel Colour" New topic
Author

Determining Pixel Colour

Jonathan Steel
Greenhorn

Joined: Jan 26, 2005
Posts: 13
Hi

Im trying to figure out how you can determine the colour of a pixel in the buffer of a JPanel.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You can't do that easily. Usually, to get a pixel valuem, one is buffering in a java.awt.image.BufferedImage and uses its getRGB method. You can scrape pixels off the screen, but that be nasty.


There is no emoticon for what I am feeling!
Jonathan Steel
Greenhorn

Joined: Jan 26, 2005
Posts: 13
Thanks for the reply.

I guess ill have to go the back buffer route then. I had hoped i could circumvent that option because Im trying to make a 4K game and this approach is sure to eat up some precious bytes.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Another approach could be to "calculate" the pixel from the application state of your program. For example, if I were writing a chess game, given a (x,y) location I would check if the location was on the board or not; if on the chess board, if there was a piece on that square; if there was a piece, take the piece's image...
Jonathan Steel
Greenhorn

Joined: Jan 26, 2005
Posts: 13
Gotcha. I cant take that route though because Im actually using the buffer to store the information about my game world. Strange, I know. Im doing this because there will be debris all over the screen not very easily represented by any data structures due to the operations ill be performing on them. I want to know the colour of a pixel to use for collision detection.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Determining Pixel Colour