使用 UIImageWriteToSavedPhotosAlbum() 保存图像后获取 ReferenceURL

发布于 2024-12-02 08:18:18 字数 878 浏览 0 评论 0原文

我想获取使用 UIImageWriteToSavedPhotosAlbum() 保存到相机胶卷中的图像的引用 URL。 iOS 4.1或以上版本可以使用AssetLibrary轻松完成。

ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL* url, NSError* error) {
    if (error == nil) {
        savedURL = url;
    }
};    
UIImage * originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSMutableDictionary * metadata = (NSMutableDictionary *)[info objectForKey:UIImagePickerControllerMediaMetadata];  
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:originalImage.CGImage
                             metadata:metadata
                      completionBlock:completionBlock];

但是,对于早期的 iO​​S,我无法找到一种聪明的方法,其中将图像保存到相机库的唯一方法是 UIImageWriteToSavedPhotosAlbum()。我想到的一种方法是使用 ALAssetsGroup 等查看保存的图像。这对我来说并不聪明,它只对 iOS 4.0 有帮助。

提前谢谢你,

Kiyo

I want to obtain the referenceURL to the image that I saved into camera roll using UIImageWriteToSavedPhotosAlbum().
iOS 4.1 or above can do it easily by using AssetLibrary.

ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL* url, NSError* error) {
    if (error == nil) {
        savedURL = url;
    }
};    
UIImage * originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSMutableDictionary * metadata = (NSMutableDictionary *)[info objectForKey:UIImagePickerControllerMediaMetadata];  
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:originalImage.CGImage
                             metadata:metadata
                      completionBlock:completionBlock];

But, I cannot figure out a smart way in case of earlier iOS where the only way of saving an image to the camera library is UIImageWriteToSavedPhotosAlbum(). One way I think about is looking around the saved image using ALAssetsGroup etc. This is not smart for me, and it only helps iOS 4.0.

Thank you in advance,

Kiyo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半﹌身腐败 2024-12-09 08:18:18

使用 writeImageToSavedPhotosAlbum 代替:

[library writeImageToSavedPhotosAlbum:[originalImage CGImage] orientation:(ALAssetOrientation)[originalImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  // oops, error !
    } else {  
        NSLog(@"url %@", assetURL);  // assetURL is the url you looking for 
    }  
}];  

Use writeImageToSavedPhotosAlbum instead:

[library writeImageToSavedPhotosAlbum:[originalImage CGImage] orientation:(ALAssetOrientation)[originalImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  // oops, error !
    } else {  
        NSLog(@"url %@", assetURL);  // assetURL is the url you looking for 
    }  
}];  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文