UIImage對象好像是不能直接去比較是否相同的,很奇怪,明明是OC對象,但是OC卻沒有做類似地址哈希值快速記錄這種.目前可以比較的方法是把它轉換成二進制,再去比較這兩段二進制是否相同.
代碼:
NSString* file = [dic stringByAppendingPathComponent:path];
UIImage *image = [UIImage imageWithContentsOfFile:file];
NSData *data1 = UIImagePNGRepresentation(image1);
NSData *data = UIImagePNGRepresentation(image);
if ([data isEqual:data1]) {
NSLog(@"is equae");
}