aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Image Comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image Comparison" Watch "Image Comparison" New topic
Author

Image Comparison

Visakh Menon
Greenhorn

Joined: Aug 20, 2003
Posts: 4
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
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Please define "is the right image". What would or wouldn't make it "the right image"?
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Visakh Menon
Greenhorn

Joined: Aug 20, 2003
Posts: 4
I mean I need to verify if the ImageIcon is created on the same gif file - verify if the name, size, height, width etc are matching with the gif file I have in my file system.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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.


GenRocket - A Test Data Generation Platform
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Comparison
 
Similar Threads
Checksum for Image comparison
image comparisons
Help - Reporting mechanism in TestNG.
Hindi
how to represent a foreign key in erd