如何将照片从相机胶卷复制到应用程序的文档文件夹作为JPG / PNG?

时间:2011-07-05 14:00:30

标签: iphone

如何将照片从相机胶卷复制/移动到应用程序自己的文档文件夹? UIImagePickerController通过以下方式返回UIImage *

(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]

如何将UIImage *保存为文件(最好嵌入所有EXIF信息)?

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码

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];