muckz
muckz

Reputation: 1

How to uniquely identify an image chosen by UIImagePicker?

I searched the web and didn't find the answer, so I thought I give it one last shot here. In my app the user has the possibility to choose images from the photo library. I don't want the user to be able to choose the same picture twice, so I am searching for a way to identify an image and to compare it to the already chosen ones. As far as I know, one is not able to get the image-URL or any other identifier for an image from the library, so I am a bit stuck. One (perhaps) possible way I thought of is to compare MD5-Checksums, but I think this is to expensive.

So thanks for your help in advance and please excuse my rusty English.

Muckz

Upvotes: 0

Views: 775

Answers (5)

KingofBliss
KingofBliss

Reputation: 15115

Use the imagePickerController delegate. Here is a sample code,

-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{

UIImage *image=[[UIImage alloc] init];
image=[info objectForKey:UIImagePickerControllerOriginalImage];
//store the image
//comparision code

}

Upvotes: 2

djromero
djromero

Reputation: 19641

Unless it's actually very slow, MD5-Checksums are probably the best method. This way you don't need to keep on memory all previously selected images to be able to compare. You just need to keep around its checksums.

Another possibility can be to choose randomly a few pixels and save its positions and color values. Then, when a new pict is selected, you can verify that previously saved pixel/colors doesn't match. It's possible that this method fails, but it's probably good enough and fast.

Upvotes: 1

Evan Mulawski
Evan Mulawski

Reputation: 55334

If you use the UIImagePickerControllerDelegate protocol, there is a method imagePickerController:didFinishPickingMediaWithInfo:. When this method is called, store the info NSDictionary in an array (maybe in your App Delegate). If another image is picked, compare the selected NSDictionary with the previous ones you stored using isEqualToDictionary:. No two images will have the same metadata. (Metadata is only available for newly captured media.)

Upvotes: 0

Luke Mcneice
Luke Mcneice

Reputation: 2720

If you have a pointer to the ImageView's then a really Quick and cheap cheap way of doing this would be to set the .tag of the UIImageView to 1 when its been selected then check it with if(UIImageView.tag)

Upvotes: -1

Christophe Debove
Christophe Debove

Reputation: 6296

Put your Image into an NSMutableArray then when the user select another time check if the selection is into the array...

Upvotes: 0

Related Questions