How can I save an image (like using UIImageWriteToSavedPhotosAlbum() method) with a filename of my choice to the private/var folder?
+1
A:
UIImageWriteToSavedPhotosAlbum()
is only used for saving to the photos camera roll. To save to a custom folder, you need to convert the UIImage into NSData with UIImageJPEGRepresentation()
or UIImagePNGRepresentation()
, then save this NSData to anywhere you like.
KennyTM
2010-02-15 09:16:10
Kenny, thanks. +1
erastusnjuki
2010-02-16 02:57:06
+1
A:
Kenny, you had the answer! For illustration I always think code is more helpful.
//I do this in the didFinishPickingImage:(UIImage *)img method
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
//save to the default 100Apple(Camera Roll) folder.
[imageData writeToFile:@"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO];
erastusnjuki
2010-02-16 02:56:24
What version of iOS is your device? I tested this with up to 3.1.3. Maybe different with iOS4.But you can find out the images path names using iPhone Explorer - http://www.macroplant.com/iphoneexplorer/
erastusnjuki
2010-08-31 11:41:51
A:
Your program is not allowed to save things outside of its "sand box" try saving it to the programs documents folder.
Eric Fode
2010-09-27 15:58:03