2015-12-22 54 views
1

我正在为IOS调用一个称为重复图像查找器的应用程序。 我的问题是如何比较图像数组以找到重复。 假设我有图像数组,我想从这个数组中找到重复的图像。 我怎么找到它?有什么建议么。 我使用的方法是将图像转换为数据,并将图像彼此的数据进行比较,在模拟器中完美地工作,但在设备中无法正常工作。如何比较图像阵列以在ios中查找重复图像

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]]]; 
    } 
} 
+0

我试过,但在实际的设备 – Harshit

回答

2

我喜欢在我的项目比较图像数据。它工作得很好,如果你也想尝试:

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); 

现在你需要从你的imageData得到的字符串:

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

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

} 
+0

不工作,但我与当地工作Photo应用程序...我从照片应用程序获取所有图像,并找到它的重复... – Harshit

+0

你使用任何类型的分页获取图像数组? –

+0

y ......................... – Harshit