This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the background color of an ImageIcon
 
Similar Threads
Changing an applet background color
JLabel and ImageIcon question
RGB values for JLabel
Background color of ImageIcon in a JTable
Background Pattern for a Cell in JTable