我知道在iOS中拍摄视频和照片时,相机会自动调节曝光。您想要了解以下内容:
1.如何关闭相机的自动曝光?
2.在Swift代码中,如何将相机的曝光设置为“零”,使曝光完全中性且不进行光线补偿?
1.如何关闭相机的自动曝光?
2.在Swift代码中,如何将相机的曝光设置为“零”,使曝光完全中性且不进行光线补偿?
您可以通过设置“AVCaptureExposureMode”属性来设置曝光模式。此处有文档。
var exposureMode: AVCaptureDevice.ExposureMode { get set }
需要考虑的三个问题:
1) 使用 "isExposureModeSupported" 检查设备是否实际支持此功能。
2) 在调整曝光之前,必须进行“锁定配置”。在此处查阅相关文档。
3) 曝光是通过设置 ISO 和持续时间来调整的。不能将其简单地设置为“0”。
此属性通过应用于信号的增益值来返回传感器对光线的灵敏度。仅支持介于 minISO 和 maxISO 之间的曝光持续时间值。较高的值将导致图像噪声。可以随时读取该属性值,而不管曝光模式如何,但只能使用 setExposureModeCustom(duration:iso:completionHandler:) 方法进行设置。
import AVFoundation
enum Esposure {
case min, normal, max
func value(device: AVCaptureDevice) -> Float {
switch self {
case .min:
return device.activeFormat.minISO
case .normal:
return AVCaptureDevice.currentISO
case .max:
return device.activeFormat.maxISO
}
}
}
func set(exposure: Esposure) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
if device.isExposureModeSupported(.custom) {
do{
try device.lockForConfiguration()
device.setExposureModeCustom(duration: AVCaptureDevice.currentExposureDuration, iso: exposure.value(device: device)) { (_) in
print("Done Esposure")
}
device.unlockForConfiguration()
}
catch{
print("ERROR: \(String(describing: error.localizedDescription))")
}
}
}
{ get set }
确切的意思吗? - user4806509