File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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.
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.
I agree. Here's the link:
subject: Getting the background color of an ImageIcon
It's not a secret anymore!