Hi all I need to verify the icon displayed on the frame is the right image. Assuming I can get hold of the ImageIcon object from the GUI, and I have the image gif files in my file system, what is the best way to do a comparison ? Thanks in advance Vis
You can get an Image object from an ImageIcon, imageIcon.getImage(), and then you can get the height and width of the image that way. The name should be pretty simple to get. Not sure about the size. Are you talking file size? You will probably need to use the IO API and the File object to get the size of the image if you mean file size.
Filenames aren't associated with Image objects in Java... Images can be built completely in memory without ever touching a file. You can get height and width, but you can scale an image, and so this won't be accurate either. The most accurate solution (but personally I think this is overkill... visual comparison would be so much simpler, unless you have to do this through a program...) would be to scale the image from the file to the same size as the image from the frame and then do a pixel by pixel comparison. There's still got to be some leeway, both at the pixel level and at the image level, but this is really the only way to do a programmatic image comparison. Oh, and to get the pixels from an Image either use PixelGrabber or a BufferedImage.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.