Reputation: 1
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
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
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
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
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
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