Skip to content

Instantly share code, notes, and snippets.

@pi-chan
Last active December 14, 2016 12:52
Show Gist options
  • Save pi-chan/7800758 to your computer and use it in GitHub Desktop.
Save pi-chan/7800758 to your computer and use it in GitHub Desktop.
compare uiimage by md5 hash
- (void)md5HashFromUIImage:(UIImage*)image
hash:(unsigned char*)hash
{
CGDataProviderRef dataProvider = CGImageGetDataProvider(image.CGImage);
NSData *data = (NSData*)CFBridgingRelease(CGDataProviderCopyData(dataProvider));
CC_MD5([data bytes], [data length], hash);
}
- (BOOL)compareUIImages:(UIImage*)image1
image:(UIImage*)image2
{
unsigned char hash1[CC_MD5_DIGEST_LENGTH];
unsigned char hash2[CC_MD5_DIGEST_LENGTH];
[self md5HashFromUIImage:image1 hash:hash1];
[self md5HashFromUIImage:image2 hash:hash2];
return memcmp(hash1, hash2, CC_MD5_DIGEST_LENGTH) == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment