比较两个图像是否相同(iOS) [英] Comparing two images whether same or not (iOS)

查看:239
本文介绍了比较两个图像是否相同(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何比较一个图像与另一个图像,以查看它们是否相似一定百分比,在iPhone?

我发现了这段代码,我想更好地理解它:

I've found this code and am trying to understand it better:

UIImage *img1 = // Some photo;
UIImage *img2 = // Some photo;

NSData *imgdata1 = UIImagePNGRepresentation(img1);

NSData *imgdata2 = UIImagePNGRepresentation(img2);

if ([imgdata1 isEqualToData:imgdata2]) {
    NSLog(@"Same Image");
}

这是否会确认图像1与图像2完全相同?这种方法是最佳实践,还是有更好的方法?

Will this confirm that image 1 is exactly the same as image 2? Is this method best practice, or is there a better approach to this?

推荐答案

您的代码是逐位比较两个图像,所以是的,它是100%的比较。

Your code is comparing the two images bit by bit, so yes it's a 100%-comparison.

如果你需要更快的东西,你可以从每个 UIImage 并比较两个哈希值,如此处所述。

If you need something faster you can generate an hash from each UIImage and compare the two hashes, as explained here.

这篇关于比较两个图像是否相同(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆