swift - 我如何同步 AVCaptureDevice setFocusModeLockedWithLensPosition 调用

标签 swift avfoundation avcapturesession avcapturedevice

我想同步 setFocusModeLockedWithLensPosition、setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains 和 setExposureModeCustomWithDuration 调用。

调用这些函数是否有逻辑顺序?

我想做的是在我确定焦点、平衡和曝光设置正确时开始运行 session (我想设置值,而不是自动设置)

我尝试锁定配置,然后调用 3 个函数,然后解锁,然后在 session 上开始运行。我将 nil 放入 3 个完成处理程序参数中。 我在这种情况下看到的是我的图像预览不漂亮(有点像蓝色滤镜)。我必须等待才能获得良好的图像质量。我想要的是仅在图像良好时显示图像。我想收到通知。

所以我尝试将我的 3 个调用与完成处理程序级联。在某些情况下,不会调用完成处理程序。我想这是我想将镜头位置设置为 0.4 而当前镜头位置为 0.4 的时候。

所以我不知道哪种方法最好。

谢谢

最佳答案

您可以像这样在完成处理程序中设置相机选项。它将等到焦点设置好后才设置曝光,同样的原理也适用于白平衡和曝光。您可以阅读有关相机设置的更多信息 here .

var AVCGains:AVCaptureWhiteBalanceGains = AVCaptureWhiteBalanceGains()
AVCGains.redGain = 1.0;
AVCGains.greenGain = 1.0;
AVCGains.blueGain = 1.0;

self.camera?.focusMode = .locked
self.camera?.exposureMode = .locked
self.camera?.whiteBalanceMode = .locked

self.camera?.setFocusModeLockedWithLensPosition(focus_point, completionHandler: {(timestamp:CMTime) -> Void in   
        print("Focus applied")
        self.camera?.setExposureModeCustomWithDuration(CMTimeMake(1,10), iso: 100, completionHandler: {(timestamp:CMTime) -> Void in 
              print("Exposure applied")
              self.camera?.setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains(AVCGains, completionHandler: {(timestamp:CMTime) -> Void in
                      print("White Balance applied")
                      // All settings have been applied, start running session 
              })
        })
})

关于swift - 我如何同步 AVCaptureDevice setFocusModeLockedWithLensPosition 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41513510/

相关文章:

swift - for循环中的额外数据

swift - AVCaptureMetadataObjectDelegate 未收到回调

具有关联类型的 Swift 协议(protocol) - 类型可能不会引用自身作为要求

ios - 隐藏状态栏 iOS

ios - iOS 模拟器上的 AVAuthorizationStatusNotDetermined

IOS/swift/AVSpeechSynthesizer : Control Speed of Enqueued Utterances

ios - 为什么使用新的 iOS 7 API 扫描条形码真的很慢?

iOS : Video recording using avcam in landscape mode?

ios - AVCaptureSession 和 AVCaptureMovieFileOutput 帧时间戳

ios - 应用程序在 iOS 8.4 上崩溃