Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-24-2011, 05:59 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: Delhi, India
Posts: 5
Archangel is on a distinguished road
Question Unique filenames based on content?

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)?
Archangel is offline   Reply With Quote
Old 01-24-2011, 09:50 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

maybe an hash (md5?) of the bytes......but i would use link if possible.
__________________
dany_dev is offline   Reply With Quote
Old 01-24-2011, 11:46 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: Delhi, India
Posts: 5
Archangel is on a distinguished road
Default

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?)
Archangel is offline   Reply With Quote
Old 01-24-2011, 12:20 PM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you can use a nsdictionary where you store the link and the path, so checking for a particolaur link is really easy.

Regarding hashing, depend on the image, you can limit the bytes to create the hash.

here how to use md5.
iphone - MD5 algorithm in Objective C - Stack Overflow
__________________
dany_dev is offline   Reply With Quote
Old 01-24-2011, 12:46 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: Delhi, India
Posts: 5
Archangel is on a distinguished road
Default

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.
Archangel is offline   Reply With Quote
Old 01-24-2011, 12:57 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: Delhi, India
Posts: 5
Archangel is on a distinguished road
Default

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!
Archangel is offline   Reply With Quote
Reply

Bookmarks

Tags
nsdata, nsfilemanager, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 366
12 members and 354 guests
7twenty7, Clouds, dre, EvilElf, iAppDeveloper, jeroenkeij, Mah6447, Morrisone, sacha1996, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,899
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:42 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0