Tuesday, July 5, 2022
HomeiOS Developmentios - How one can deal with a video overexposure in Swift

ios – How one can deal with a video overexposure in Swift


I am engaged on a digital camera app, and I feel the conduct of my app and the iPhone default digital camera app in opposition to overexposure could be very completely different.

Just like the picture under, the default digital camera app adjusts the overexposure when it is detected. (I really feel the entire display will get barely yellow-ish to eliminate the overexposed brightness space. So I can see the white keyboard even placing darkish stuff covers a lot of the display.

enter image description here

Right here is my app and I set the publicity mode to the steady publicity mode, but it surely will not regulate the overexposed space.

enter image description here

I wish to regulate the brightness, however I additionally do not wish to show the picture together with the overexposed half (I imply… I simply need my app to indicate just like the default digital camera does.)

That is the code for regulate the main focus and publicity.

    func setFocus(with focusMode: AVCaptureDevice.FocusMode, with exposureMode: AVCaptureDevice.ExposureMode, at level: CGPoint, monitorSubjectAreaChange: Bool, completion: @escaping (Bool) -> Void) {
    guard let captureDevice = captureDevice else { return }
    do {
        strive captureDevice.lockForConfiguration()
    } catch {
    if captureDevice.isSmoothAutoFocusSupported, !captureDevice.isSmoothAutoFocusEnabled { captureDevice.isSmoothAutoFocusEnabled = true }
    if captureDevice.isFocusPointOfInterestSupported, captureDevice.isFocusModeSupported(focusMode) {
        captureDevice.focusPointOfInterest = level
        captureDevice.focusMode = focusMode
    if captureDevice.isExposurePointOfInterestSupported, captureDevice.isExposureModeSupported(exposureMode) {
        captureDevice.exposurePointOfInterest = level
        captureDevice.exposureMode = exposureMode
    captureDevice.isSubjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange

and that is how I name the operate

func setFocusToCenter() {
    let middle: CGPoint = CGPoint(x: cameraView.bounds.width / 2, y: cameraView.bounds.top / 2)
    let pointInCamera = cameraView.layer.captureDevicePointConverted(fromLayerPoint: middle)
    setFocus(with: .continuousAutoFocus, with: .continuousAutoExposure, at: pointInCamera, monitorSubjectAreaChange: false, completion: { [weak self] success in
        guard let self = self, success else { return }
        // do some animation

if I have to work on the digital camera publicity and even when I set the ExposureMode as steady auto publicity, do I nonetheless have to deal with overexposure in code?
Additionally, if in case you have skilled for adjusting the overexposure, how did you obtain that?



Most Popular

Recent Comments