首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ios中获取当前的自动对焦系统时崩溃

在ios中获取当前的自动对焦系统时崩溃
EN

Stack Overflow用户
提问于 2015-01-05 02:39:27
回答 1查看 339关注 0票数 0

IPhone6介绍了两种聚焦检测方法: 1.对比度检测2.相位检测

在iphone 6.6+中,它使用相位检测。

我想要得到当前的焦点系统

代码语言:javascript
复制
self.format = [[AVCaptureDeviceFormat alloc] init];
[self.currentDevice setActiveFormat:self.format];

AVCaptureAutoFocusSystem currentSystem = [self.format autoFocusSystem];
if (currentSystem == AVCaptureAutoFocusSystemPhaseDetection)
{
     [self.currentDevice addObserver:self forKeyPath:@"lensPosition"    options:NSKeyValueObservingOptionNew context:nil];
}
else if(currentSystem == AVCaptureAutoFocusSystemContrastDetection)
{
  [self.currentDevice addObserver:self forKeyPath:@"adjustingFocus" options:NSKeyValueObservingOptionNew context:nil];
}
else{
    NSLog(@"No observers added");
}

但是现在它在下面这一行崩溃了

代码语言:javascript
复制
AVCaptureAutoFocusSystem currentSystem = [self.format autoFocusSystem];

我找不到坠机的适当描述。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-05 03:14:19

您正在创建一些"AVCaptureDeviceFormat",但实际上在默认情况下不会使用它设置任何内容。它只是无法使用的垃圾(这就是为什么你要崩溃)。

每个捕获设备都有一到两种可以使用的格式。

你可以通过做这样的事情来看到它们:

代码语言:javascript
复制
for (AVCaptureDeviceFormat *format in [self.currentDevice formats]) {
       CFStringRef formatName = CMFormatDescriptionGetExtension([format formatDescription], kCMFormatDescriptionExtension_FormatName);
       NSLog(@"format name is %@", (NSString *)formatName);
}

您应该做的是决定要使用哪个AVCaptureDevice (例如,前摄像头、后置摄像头等),从那里获取的格式,然后设置[self.currentDevice setActiveFormat:self.format]“。

WWDC 2013年的会议“什么是新的相机捕捉”视频有更多关于如何做到这一点的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27772728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档