I am trying to store the images picked using UIImagePicker in the Documents folder of my app. I would like to name these images uniquely based on the image, so that even if the user picks the same image second time, it doesn't get stored again. Is there a way I can name the file uniquely on the basis of contents (UIImage here)?
I need to store the images. But even if I use links, I would have trouble to check for duplicity. In case of files, I can simply check if the file already exists or not.
Regarding hashes, would it be fast enough to hash the whole image data? And then name the file as first few characters of that hash?
Also, could you please give an example as to how I can hash an image data? (Hash the UIImagePNGRepresentation data?)
Thanks a lot Dany. I will try that hash function for file naming.
Since I want to persist the images even if they are deleted from the phone album, I won't use NSDictionary. I also need to store images from other sources, including camera and web, so having a photo album of my own makes more sense (or just populate the iphone's photo album? and use nsdict as you suggest?).
I will post an update if this works for me. Thanks again.
Saving the images again does take up double the memory for the same data, and perhaps I should actually use links. The only concern is what if user deletes that image from the album. I would need to check for the availability of image and delete the link if it returs no image, every time I try to load the image.
So which one seems better solution - links or saving images? Some advice please..
Thanks!