Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the background color of an ImageIcon

 
Sarone Thach
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic