使用 UIImageWriteToSavedPhotosAlbum() 保存图像后获取 ReferenceURL
我想获取使用 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];
但是,对于早期的 iOS,我无法找到一种聪明的方法,其中将图像保存到相机库的唯一方法是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 writeImageToSavedPhotosAlbum 代替:
Use writeImageToSavedPhotosAlbum instead: