我有一个应用程序,在拍摄静态照片之前创建自己的实时预览.应用程序需要对图像数据运行一些处理,因此无法依赖AVCaptureVideoPreviewLayer.使用Apple的示例代码,使初始流工作进展顺利.当我尝试切换到更高质量的图像拍摄快照时出现问题.响应按钮按下,我尝试重新配置会话以拍摄全分辨率照片.我尝试了很多变化,但这是我最新的例子(仍然不起作用):
- (void)sessionSetupForPhoto
{
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureStillImageOutput *output = [[[AVCaptureStillImageOutput alloc] init] autorelease];
for (AVCaptureOutput *output in [session outputs]) {
[session removeOutput:output];
}
if ([session canAddOutput:output]){
[session addOutput:output];
} else {
NSLog(@"Not able to add an AVCaptureStillImageOutput");
}
[session commitConfiguration];
}
Run Code Online (Sandbox Code Playgroud)
我一直在commitConfiguration行之后收到一条错误消息,如下所示:(也就是说,我收到AVCaptureSessionRuntimeErrorNotification发送给我的注册观察者)
收到错误:NSConcreteNotification 0x19d870 {name = AVCaptureSessionRuntimeErrorNotification; object =; userInfo = {AVCaptureSessionErrorKey ="Error Domain = AVFoundationErrorDomain Code = -11800 \"操作无法完成.(AVFoundationErrorDomain错误-11800.)\"UserInfo = 0x19d810 {}";
XCode中的文档表面上提供了有关错误编号(-11800)的更多信息,"AVErrorUnknown - 错误原因未知.";
以前我也尝试过调用stopRunning和startRunning,但是在观看WWDC Session 409之后不再这样做了,不鼓励这样做.当我停止并开始时,我得到一个不同的错误消息-11819,它对应于"AVErrorMediaServicesWereReset - 操作无法完成,因为媒体服务变得不可用.",这比简单的"未知"要好得多,但不一定更有帮助.
它成功添加了AVCaptureStillImageOutput(即,不发出日志消息).
我正在测试iPhone 3g(w/4.1)和iPhone 4.
这个调用发生在主线程中,这也是我原来的AVCaptureSession设置发生的地方.
如何避免错误?如何切换到更高的分辨率拍摄照片? …