简体   繁体   English

OS X:比较两个图像

[英]OS X: Comparing two images

I'm trying to implement a way to compare two images but I'm testing my and comparing the same image to make sure is working but doesn't work. 我正在尝试实现比较两个图像的方法,但我正在测试我并比较相同的图像以确保工作但不起作用。 here is may code: 这里可能是代码:

NSImage *file = [[NSImage alloc] initWithContentsOfFile:path];
NSData *imgDataOne = [file TIFFRepresentation];
NSData *imgDataTwo = [file TIFFRepresentation];

if (imgDataOne == imgDataTwo)
{
    NSLog(@"is the same image");
}

The if is never true. if永远不会是真的。 Any of you knows what I'm doing wrong or if another way to compare the images? 你们中的任何人都知道我做错了什么,或者是否有其他比较图像的方式?

I'll really appreciate your help. 我真的很感谢你的帮助。

TIFFRepresentation will return a new NSData object. TIFFRepresentation将返回一个新的NSData对象。 Comparing these objects using the == operator will always return false because these are two different objects. 使用==运算符比较这些对象将始终返回false,因为这些是两个不同的对象。

NSData has isEqualToData method to test if these two NSData objects contain the same binary data. NSData有isEqualToData方法来测试这两个NSData对象是否包含相同的二进制数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM