iphone - 使用 writeImageToSavedPhotosAlbum 将 UIImage 保存到相册

标签 iphone objective-c ios alassetslibrary

我正在尝试将 UIImage 保存到相册。我尝试了几种方法,最后一种是:

-(IBAction)captureLocalImage:(id)sender{

[photoCaptureButton setEnabled:NO];

// Save to assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum: imageView.image.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error2)
 {
     //             report_memory(@"After writing to library");
     if (error2) {
         NSLog(@"ERROR: the image failed to be written");
     }
     else {
         NSLog(@"PHOTO SAVED - assetURL: %@", assetURL);
     }

     runOnMainQueueWithoutDeadlocking(^{
         //                 report_memory(@"Operation completed");
         [photoCaptureButton setEnabled:YES];
     });
 }];  

}

imageView 是一个 UIImageView,其中包含我要保存的图像。 在日志中我得到“照片已保存 - assetURL:(空)”并且照片未保存到库中。

我做错了什么?

最佳答案

只需使用这条波纹管将图像保存在您的照片库中

UIImageWriteToSavedPhotosAlbum(imageView.image,nil,nil,nil);

:)

关于iphone - 使用 writeImageToSavedPhotosAlbum 将 UIImage 保存到相册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12688610/

相关文章:

ios - didFailWithError : Error Domain=kCLErrorDomain Code=0 "The operation couldn’ t be completed.(kCLErrorDomain 错误 0。)”

ios - 在后台的 iPhone 7 上未调用应用程序 DidReceiveRemoteNotification

iphone - 取消按钮在 iPhone 短信集成中不起作用

ios - 使用 SwiftMessages pod 同时显示两条消息

ios - iAD 横幅 - 未在应用商店中显示

iphone - IOS CATransform3DMakeRotation 需要矢量方面的帮助

ios - 循环后如何在主队列上重新加载表(Objective-c)

iphone - 向 MP4 视频添加效果?

iphone - 应用程序激活时删除模态视图 Controller

iphone - ALAssetsLibrary enumerateGroupsWithTypes 不返回任何数据