Reputation: 184
i am comparing images with each other here is the code for it.
for (int i=0; i<arrImageData.count; i++)
{
for (int j=i+1; j<arrImageData.count; j++)
{
if ([arrImageData[i]isEqualToData:arrImageData[j]])
{
[arrImages addObject:arrImage[i]];
}
}
}
now problem is when number of images increase it takes too much time to calculate.is there any better solution for it?
Upvotes: 1
Views: 467
Reputation: 5369
You can use Fast Enumeration as Below
for(UIImage *img in arrImageData)
{
for (UIImage *comImg in arrImageData) {
if ([UIImageJPEGRepresentation(img, 0) isEqual:UIImageJPEGRepresentation(comImg, 0)]) {
[arrImages addObject:img];
}
}
}
Hope it helps you...!
Upvotes: 0
Reputation: 1557
you should use hashes to compare big amount of data
1 you can compare UImage directrly: image1.hash == image2.hash
2 you can calculate your own hash for each image added to the array, it will be calculated once and used for every comparison
here is the hash algorithm https://en.wikipedia.org/wiki/MD5
PS it will works if image data is absolutely equal, it much more difficult to compare two different images with one "content" Image comparison - fast algorithm
Upvotes: 1
Reputation: 597
you can try something like this:
- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2{
return [UIImagePNGRepresentation(image1) isEqual:UIImagePNGRepresentation(image2)];
}
Upvotes: 0
Reputation: 438
I think you should use hashes for comparison. Refer this link: Generate hash from UIImage It will help you.
Upvotes: 1