wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Getting the background color of an ImageIcon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting the background color of an ImageIcon" Watch "Getting the background color of an ImageIcon" New topic
Author

Getting the background color of an ImageIcon

Sarone Thach
Ranch Hand

Joined: Jun 25, 2003
Posts: 89
Hi all,
Is there an easy way or any way of getting the background color of an imageicon.
Do tell me if this is a stupid question, because from my angle it appears to be valid.
I have an ImageIcon that has a green background, I would like to set the background of the panel that I'm placing it on the same color.
thanks.
Sarone
kyle amburn
Ranch Hand

Joined: Jul 29, 2001
Posts: 64
Since an ImageIcon is created from Image data (i.e gif, jpeg) I assume the background you are trying to determine is part of the image. The only way I know to determine the bg would be to use a PixelGrabber for the image and determine its color model. However to do this you would have to either 1) know the x,y of a background pixel or 2) write a method that examines every pixel and determines the background based upon the most occurences of any one Color(this is obviously not perfect).
If you know, the image color going in, you would be better off just getting the Color values (r,g,b,a) from your image editing program and then coding in this color.
Kyle
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting the background color of an ImageIcon
 
Similar Threads
JLabel and ImageIcon question
Background Pattern for a Cell in JTable
Background color of ImageIcon in a JTable
Changing an applet background color
RGB values for JLabel