[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

Java Comparing Image Files

I would like to create an java program which interacts with another application on my desktop, by frequently taking screenshot and comparing this with the last screenshot, the program should be able to detmind what if anything has changed and than act accordingly.

I have worked out that i can take screenshots using the robot class and store them into a BufferedImage but how do i now compare the two files, it would be useful to break the image down into manageable chunks.

Thanks for any help you are able to offer me.
  • 3
3 Solutions
Mayank SAssociate Director - Product EngineeringCommented:
You can get pixels from a buffered-image using this:


- and then compare both the files, if that helps.

if you can get all the pixels in a array like in that example, then you can compare them using Arrays.equals()
Mayank SAssociate Director - Product EngineeringCommented:
If you have them saved in a file, you can also try some file-comparision utility.
Hi sjw11

You can use a PixelGrabber http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/PixelGrabber.html and compare the pixels fo the images one by one. Just make sure you are encoding the images with the same algorithm (jpeg, bmp etc) every time.

Mayank SAssociate Director - Product EngineeringCommented:
Duh~! I knew I was forgetting that ;-)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now