【发布时间】:2015-12-27 04:41:59
【问题描述】:
为 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 比例的东西都应被视为焦点和曝光点,超出此范围的任何东西都不会被视为相机对焦的触摸事件。
【问题讨论】:
-
你在使用 AVCaptureVideoPreviewLayer 吗?如果是这样:
public func captureDevicePointOfInterestForPoint(pointInLayer: CGPoint) -> CGPoint -
@jlw 是的,我正在使用
AVCaptureVideoPreviewLayer,但我没有看到该功能。 :// -
@jlw 哇,我怎么会错过呢?请纠正你的答案,我会接受的。谢谢
标签: ios swift camera avfoundation swift2