Reputation: 2759
I want to compare an image that I am downloading from a server to an image saved to the bundle to see if its the same image. How would I accomplish this in iOS?
Thanks!
Shredder
Upvotes: 0
Views: 219
Reputation: 4413
If images are expected to be exactly the same, not recompressed or anything, you can load both in NSData
object and compare it with isEqualToData:
.
If they might have different metadata, but the image is still the same, then you can load them as images and compare actual image pixels using decoding similar to this one: How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?.
If they are similar, but may be of different format or recompressed, then you'd need image comparison software, e.g. OpenCV.
Upvotes: 2
Reputation: 56635
If you want to know if it's the same image then you should just use a hash function.
If you have decided on what hash function should be used then you can even have the server send you the hash of the image and compare it with your local hash of the image instead of sending you the image itself.
If the hash matches then there is no need to download the image at all. If on the other hand the hashes differ then you know that you need to download the new image.
Upvotes: 2
Reputation: 323
firstly you can compare image sizes then sizes are same then you can use answer at Image comparison
Upvotes: 0