UIImageWriteToSavedPhotosAlbum - 无法对保存的照片的图像进行编码

时间:2012-08-24 23:05:37

标签: ios uiimage

在我的主ViewController中,我从UIGraphicsGetImageFromCurrentImageContext()生成一个图像。图像被分配给UIImage,我已经通过在主视图中放置UIImageView来测试它,所以我可以看到它。工作得很好。但是,当我点击我指定保存的按钮时,我收到错误:-3304 "Failed to encode image for saved photos."

截图代码:

 CGSize mySize = CGSizeMake(530, 350);
 UIGraphicsBeginImageContext(mySize);
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextTranslateCTM(context, -444, -313);
 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
 // self.screenshot is a UIImage declared in .h
 self.screenshot = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

保存代码:

UIImageWriteToSavedPhotosAlbum(screenshot, self, @selector(imageWasSavedSuccessfully:didSaveWithError:contextInfo:), NULL);

不确定我是否不符合相机胶卷图像的要求,或者该方法是否只能与UIPickerController类一起使用。谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

对后人来说,问题是要保存的图像为零。

答案 1 :(得分:-1)

尝试保存您的图片:

UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);

或者

UIImageWriteToSavedPhotosAlbum(self.screenshot, nil, nil, nil);

或者甚至

UIImageWriteToSavedPhotosAlbum(screenshot, self, nil, nil);