Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting pixel information from jLabel?  RSS feed

 
MR Chahal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

What would be the best way to get pixel information from a picture shown in a jlabel? I am using NetBeans 5.5.1.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you used a BufferedImage for the ImageIcon in the JLabel you can get a reference to it
and use the getRGB(int x, int y) method to get the int (Color) value for any pixel. Then
you can unpack the color components from the int.
If you didn't use a BufferedImage in the ImageIcon you have a couple of options:
1 - get a reference to the image and draw it into a BufferedImage to use as above;
2 - use the image and the PixelGrabber class to get the pixels from the image and carry on
as before. The PixelGrabber class has an example including how to unpack the color
components from the int value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!