什麼是創建一個精確的自動對焦和AVFoundation定製層相機曝光的最好辦法?比如,目前我的攝像頭預覽層是方形的,我想要將相機對焦和曝光指定爲該邊框。如果可能的話,我需要這個在Swift 2中,如果不是,請寫下你的答案,我可以自己將其轉換。自動對焦和自定義相機層AVFoundation自動曝光
當前自動對焦和曝光:但正如您所看到的,這將在對焦時評估整個視圖。
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嗎?如果是這樣的話:'公共func captureDevicePointOfInterestForPoint(pointInLayer:CGPoint) - > CGPoint' – jlw
@jlw是的我使用'AVCaptureVideoPreviewLayer',但我沒有看到這個功能。 :/ – Xrait
https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/#//apple_ref/occ/instm/AVCaptureVideoPreviewLayer/captureDevicePointOfInterestForPoint: – jlw