【发布时间】:2012-08-25 21:16:31
【问题描述】:
在我的主 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 类一起使用。感谢您的帮助。
【问题讨论】:
-
您之前是否在设备上打开过照片应用程序? self.screenshot 是零吗? (你确定你的 screenshot 变量和 self.screenshot 一样吗?)
-
@JesseRusak 你是对的......截图变量为零。我有一个弹出框来确定用户是要保存还是上传它,并且由于弹出框对其内容使用单独的视图控制器来保存保存操作,因此我需要确保正确传递了 var。 . 谢谢。