This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes See if one picture is exactly like another... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "See if one picture is exactly like another..." Watch "See if one picture is exactly like another..." New topic
Author

See if one picture is exactly like another...

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
Is there a way in java to see if a picture is exactly like another? Such as pixels, width, height, color of the pixels.

for example:

picture.equals(picture2);


Justin Fox


You down with OOP? Yeah you know me!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41060
    
  43
There is nothing predefined like this, but you can easily write this yourself. Use the javax.imagio.Imageio.read method to load both images, and then use the methods of the BufferedImage class to compare widths, heights and RGB values.


Ping & DNS - my free Android networking tools app
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Alternatively, you could also generate an MD5 hash of both images and compare the hashes. This method would not tell you specifically what is different though.
[ December 27, 2007: Message edited by: Chad Clites ]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
cool, thanks a lot.

what I'm wanting to do is, I have a game I play(mmorpg) and you kill "monsters" and stuff, and what i was going to do was take certain screencaptures with the robot class and compare them to a static picture I took and saved, if they are alike, attack that "monster".

This might not be a good way, because the likely hood of me randomly taking a screen capture that is exactly alike is almost impossible.

I had another plan though:

have about 5 or 6 different threads and have them "scanning" a current copy of the gamescreen, If i come across a certain pixel color that is that of a "monster" attack that creature, and pause all other threads.

Is this a good approach?

Thanks,

Justin
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: See if one picture is exactly like another...
 
Similar Threads
Laptop under INR 60000/1400 USD
How to create image from bufferedImage
planning to buy MacBook
Buying a MacBook
How to get the size of a string in pixels?