Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage Saving image with file name on the iPhone

How can I save an image (like using UIImageWriteToSavedPhotosAlbum() method) with a filename of my choice to the private/var folder?

like image 978
erastusnjuki Avatar asked Feb 15 '10 04:02

erastusnjuki


People also ask

How do you save in UIImage?

If you've generated an image using Core Graphics, or perhaps rendered part of your layout, you might want to save that out as either a PNG or a JPEG. Both are easy thanks to two methods: pngData() and jpegData() , both of which convert a UIImage into a Data instance you can write out.

What is UIImage?

An object that manages image data in your app.


2 Answers

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]; 
like image 91
erastusnjuki Avatar answered Oct 02 '22 19:10

erastusnjuki


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.

like image 30
kennytm Avatar answered Oct 02 '22 18:10

kennytm