1

i am working on one app called duplicate image finder for IOS. my question is how to compare image array to find duplicate. suppose i have array of images and i want to find duplicate images from this array. how can i find it? any suggestions. i have used method that is convert image to data and compare data of image with each other that works perfectly in simulator but not working properly in device.

for (int i=0; i<arrImageData1.count; i++)
    {
        for (int j=i+1; j<arrImageData1.count; j++)
        {
            if ([[arrImageData1 objectAtIndex:i] length]==[[arrImageData2 objectAtIndex:j]length])
            {
                NSNumber *iValue = [NSNumber numberWithInt:i];
                NSNumber *jValue = [NSNumber numberWithInt:j];
                [arr addObject:iValue];
                [arr addObject:jValue];
            }
        }
    }
    NSLog(@"%@",arr);
    NSLog(@"%lu",(unsigned long)arr.count);
    for (int k=0; k<arr.count; k++)
    {
        [arrDuplicateImages addObject:[arrImage objectAtIndex:[[arr objectAtIndex:k] integerValue]]];
    }
}
Harshit
  • 184
  • 9

1 Answers1

2

I preferred in my project comparing image Data. And it worked fine if you want to try :

UIImage *image = [UIImage imageNamed:@"image1.jpeg"];
NSData *imageData= UIImageJPEGRepresentation(image,0.0);
UIImage *imageDuplicate = [UIImage imageNamed:@"image1 copy.jpeg"];
NSData *imageDuplicateData= UIImageJPEGRepresentation(imageDuplicate,0.0);

now you need to get string from your imageData:

NSString *str1 = [NSString stringWithFormat:@"%@",imageData];
NSString *str2 = [NSString stringWithFormat:@"%@",imageDuplicateData];

if ([str1 isEqualToString:str2]){
    NSLog(@"same images");
} else {
    NSLog(@"images are different");

}
Shubham bairagi
  • 943
  • 7
  • 25