UIImage对象比较是否相同

作者: 日常生活干什么 | 来源:发表于2016-07-14 16:05 被阅读36次

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");
  }

 


相关文章

网友评论

    本文标题:UIImage对象比较是否相同

    本文链接:https://www.haomeiwen.com/subject/cuwejttx.html