How to compare two UIImage in iOS 8 [duplicate]

一个人想着一个人 提交于 2019-12-06 05:28:59
Dharmendra Kumar Rajan

Please compare NSData object instead of comparing UIImage Object.

-(BOOL)firstimage:(UIImage *)image1 isEqualTo:(UIImage *)image2 {
    NSData *data1 = UIImagePNGRepresentation(image1);
    NSData *data2 = UIImagePNGRepresentation(image2);

    return [data1 isEqualToData:data2];
}

I'd not rely on comparing image property with address returned by UIImage method (it could be newly allocated block I suppose).

If you really need to compare if data(image) is same you could use something like:

UIImage* checkImage = [UIImage imageNamed:@"check.png"];
NSData *checkImageData = UIImagePNGRepresentation(checkImage);
NSData *propertyImageData = UIImagePNGRepresentation(imgViewCheck.image);
if ([checkImageData isEqualToData:propertyImageData]) {
  //do sth
}

where possible I'd prefer to keep state/imageId in a variable for comparison purposes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!