Objective-C: Comparing an image against another image that has been previously saved Objective-C: Comparing an image against another image that has been previously saved objective-c objective-c

Objective-C: Comparing an image against another image that has been previously saved


You can compare the image name or the image URL if it was downloaded from Internet, it will also be faster than comparing the images.

Also, the problem is that by using the == operator you are comparing the memory addresses of the images 0x95614c0 and 0xde748f0. That's why is not equal. You are comparing if they are the same object, not if the images are equal.

To compare images use: As mentioned on Fls'Zen answer.

if ([UIImagePNGRepresentation(blackImage) isEqualToData:UIImagePNGRepresentation(greenImage)])


Your images certainly have different addresses since one is loaded from your application bundle and one is loaded from the documents directory. The [UIImage imageNamed:] function only returns images from the application bundle.

If you really want to compare the images by contents, check out this SO question. In the first answer, a hash value s computed for an image. In your code, you could compare the hash values of the two images you have. The second answer compares the images directly, in case hashes make you nervous.

I recommend going a different route and having your application track which image is loaded outside of the image itself.