0

我刚刚开始开发一个应用程序,我想在其中自动同步存储在用户照片库中的所有图像作为资产。

我能够获取存储为资产的图像的 URL。

e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG

现在,我如何将此图像复制到我的应用程序的文档目录中,或者我如何通过获取 inNSData或 in来显示存储在 assets 中的图像UIImage

提前致谢。

4

1 回答 1

1

UIImagePickerControllerDelegate您可以在委托实现中使用以下代码

- (void) imagePickerController:(UIImagePickerController *)picker
 didFinishPickingMediaWithInfo:(NSDictionary *)info {

    //obtaining saving path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"];

    //extracting image from the picker and saving it
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];

}
于 2011-04-13T12:11:21.593 回答