• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image Comparison

 
Visakh Menon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please define "is the right image". What would or wouldn't make it "the right image"?
Brian
 
Visakh Menon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic