ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?例如,目前我的相机预览图层是方形的,我希望将相机焦点和曝光指定到该帧边界.如果可能的话,我需要在 Swift 2中使用它,如果没有,请写下你的答案我可以自己转换它.

当前自动聚焦和曝光:但是正如您所看到的,这将在聚焦时评估整个视图.

override func touchesBegan(touches: Set<UITouch>,withEvent event: UIEvent?) {
    //Get Touch Point
    let Point = touches.first!.locationInView(self.capture)
    //Assign Auto Focus and Auto Exposour
    if let device = currentCameraInput {
        do {
            try! device.lockForConfiguration()
            if device.focusPointOfInterestSupported{
                //Add Focus on Point
                device.focusPointOfInterest = Point
                device.focusMode = AVCaptureFocusMode.AutoFocus
            }

            if device.exposurePointOfInterestSupported{
                //Add Exposure on Point
                device.exposurePointOfInterest = Point
                device.exposureMode = AVCaptureExposureMode.AutoExpose
            }
            device.unlockForConfiguration()
        }
    }
}

相机层:1:1比例的任何内容都应被视为焦点和曝光点,此范围之外的任何内容甚至不会被视为相机焦点的触摸事件.

解决方法

public func captureDevicePointOfInterestForPoint(pointInLayer: CGPoint) -> CGPoint

将根据您的AVCaptureVideoPreviewLayer的设置为您提供设备关注点.见docs.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...