views:

1492

answers:

4

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
Kenny, thanks. +1
erastusnjuki
+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
A: 

But that doesn't seem to work...

Ben
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
A: 

Your program is not allowed to save things outside of its "sand box" try saving it to the programs documents folder.

Eric Fode