iOS本机相机AVFoundation亮度曝光差
AVFoundation亮度/曝光与本机相机不同。是否可以使用AVFoundation framework复制本机相机设置?如果您正在寻找自动曝光,请为“调整曝光”设置一个键值观察者,并将曝光模式设置为AVCaptureExposureModeContinuousAutoExposure。如果您试图实现手动曝光,请查看此项。Swift 4.2中的自动曝光iOS本机相机AVFoundation亮度曝光差,ios,swift,Ios,Swift,AVFoundation亮度/曝光与本机相机不同。是否可以使用AVFoundation framework复制本机相机设置?如果您正在寻找自动曝光,请为“调整曝光”设置一个键值观察者,并将曝光模式设置为AVCaptureExposureModeContinuousAutoExposure。如果您试图实现手动曝光,请查看此项。Swift 4.2中的自动曝光 // MARK: Exposure Methods @objc func tapToExpose(recognizer: UI
// MARK: Exposure Methods
@objc
func tapToExpose(recognizer: UIGestureRecognizer){
if activeInput.device.isExposurePointOfInterestSupported{
let point = recognizer.location(in: camPreview)
// The tap location is converted from the `GestureRecognizer` to the preview's coordinates.
let pointOfInterest = previewLayer.captureDevicePointConverted(fromLayerPoint: point)
// Then , the second conversion is made for the coordinate space of the camera.
showMarkerAtPoint(point: point, marker: exposureMarker)
exposeAtPoint(pointOfInterest)
}
}
func exposeAtPoint(_ point: CGPoint){
let device = activeInput.device
if device.isExposurePointOfInterestSupported, device.isFocusModeSupported(.continuousAutoFocus){
do{
try device.lockForConfiguration()
device.exposurePointOfInterest = point
device.exposureMode = .continuousAutoExposure
if device.isFocusModeSupported(.locked){
// Now let us add the illumination for the `observeValueForKeyPath` method,
device.addObserver(self, forKeyPath: kExposure, options: .new, context: &adjustingExposureContext)
device.unlockForConfiguration()
}
}
catch{
print("Error Exposing on POI: \(String(describing: error.localizedDescription))")
}
}
}
// MARK: KVO
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
// First , check to make sure that the context matches the adjusting exposure context,
// Otherwise, pass the observation on to super.
if context == &adjustingExposureContext {
let device = object as! AVCaptureDevice
// then determine if the camera has stopped adjusting exposure , and if the locked mode is supported.
if !device.isAdjustingExposure , device.isExposureModeSupported(.locked){
// remove self from the observer to stop subsequent notification,
device.removeObserver(self, forKeyPath: kExposure, context: &adjustingExposureContext)
DispatchQueue.main.async {
do{
try device.lockForConfiguration()
device.exposureMode = .locked
device.unlockForConfiguration()
}
catch{
print("Error exposing on POI: \(String(describing: error.localizedDescription))")
}
}// DispatchQueue.main.async
}// if !device.isAdjustingExposure , device.isExposureModeSupported(.locked)
}// if context == &adjustingExposureContext {
else{
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}
如果
device.isFocusModeSupported(.locked)=false怎么办?那么坏消息是,您的设备无法启用耶。但是,在这种情况下解锁配置如何?