【问题标题】:Crash while getting the current Autofocus system in ios在 ios 中获取当前自动对焦系统时崩溃
【发布时间】:2015-01-05 02:39:27
【问题描述】:

从 iphone 6 介绍开始就有两种类型的焦点检测, 1.对比度检测 2.相位检测

从 iphone 6.6+ 开始,它使用相位检测。

我正在尝试获取当前的焦点系统

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");
}

但现在它在以下行中崩溃了

AVCaptureAutoFocusSystem currentSystem = [self.format autoFocusSystem];

我无法找到崩溃的正确描述。

【问题讨论】:

    标签: ios ios8 avfoundation iphone-6


    【解决方案1】:

    您正在创建一些“AVCaptureDeviceFormat”,但默认情况下实际上并没有设置任何内容。这只是无法使用的垃圾(这就是你崩溃的原因)。

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

    您可以通过执行以下操作来查看它们:

    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 会议“相机捕捉的新功能”视频提供了有关如何执行此操作的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      相关资源
      最近更新 更多