How can I copy/move a photo from Camera Roll to an app's own Documents folder? UIImagePickerController
returns a UIImage *
by:
(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]
How can I save the UIImag开发者_JAVA百科e *
as a file (best with all the EXIF information embedded)?
Try using following code
NSData *data = UIImagePNGRepresentation(image);
NSArray *UsrDocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocsDir = [UsrDocPath objectAtIndex:0];
NSString *path = [DocsDir stringByAppendingPathComponent:@"contents.png"];
//Remove if necessary
BOOL success = [FileManager fileExistsAtPath:path];
if(success){
[FileManager removeItemAtPath:path error:&error];
}
[data writeToFile:path atomically:YES];
精彩评论