Last active
December 14, 2016 12:52
-
-
Save pi-chan/7800758 to your computer and use it in GitHub Desktop.
compare uiimage by md5 hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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