user2924482
user2924482

Reputation: 9140

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. Any of you knows what I'm doing wrong or if another way to compare the images?

I'll really appreciate your help.

Upvotes: 1

Views: 1040

Answers (1)

danielv
danielv

Reputation: 3107

TIFFRepresentation will return a new NSData object. Comparing these objects using the == operator will always return false because these are two different objects.

NSData has isEqualToData method to test if these two NSData objects contain the same binary data.

Upvotes: 3

Related Questions