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.
LVL 2
sjw11Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Mayank SConnect With a Mentor Associate 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_expertConnect With a Mentor Commented:

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
 
girionisConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.