2

My application contains images in SQLite database. I want to check for duplicate values of UIImage before I insert it in to the database. The image is stored as blob type. Is this possible?

Frade
  • 2,938
  • 4
  • 28
  • 39
baiju krishnan
  • 231
  • 4
  • 14
  • you can check this link - http://stackoverflow.com/questions/843972/image-comparison-fast-algorithm. Also you can convert your blob data to NSData and then you can compare two NSData object. – rishi Apr 23 '12 at 08:24

1 Answers1

2

One way to do it would be to store a hash, like sha1, of the image data in another field of the database then compare against that.

Community
  • 1
  • 1
keegan3d
  • 10,357
  • 9
  • 53
  • 77
  • +1 specifically, this would *significantly* reduce the number of images which must be compared and make the operation very fast over large collections (databases) *although* the images with matching hashes would still need to be compared. – justin Apr 23 '12 at 08:29
  • That link for sha1 shows how to get a hash from `NSData`: http://stackoverflow.com/a/3469033/239380 – keegan3d Apr 23 '12 at 08:30
  • Iam doing like this way. NSData *imgData = UIImagePNGRepresentation(image.image); NSLog(@"imgdata=%@",imgData); UIImage *dataImage=[[UIImage alloc] init]; dataImage=[UIImage imageWithData:imgData]; NSLog(@"image new=%@",dataImage); NSString *sqlTmp=[NSString stringWithFormat:@"SELECT COUNT(*) FROM Images where imgName= '%@'",dataImage]; const char *sqlstmt=[sqlTmp UTF8String]; – baiju krishnan Apr 23 '12 at 10:42