为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.