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

x
  • 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.
0
sjw11
Asked:
sjw11
  • 3
3 Solutions
 
Mayank SAssociate Director - Product EngineeringCommented:
You can get pixels from a buffered-image using this:

http://javaalmanac.com/egs/java.awt.image/ImagePixel.html

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

if you can get all the pixels in a array like in that example, then you can compare them using Arrays.equals()
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If you have them saved in a file, you can also try some file-comparision utility.
0
 
girionisCommented:
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.

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

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