Tuesday, June 30, 2026
HomeiOS Developmentios - Why steady auto publicity will get overexposed in Swift

ios – Why steady auto publicity will get overexposed in Swift

[ad_1]

I am engaged on a digicam app and I am not likely certain how the publicity of the digicam works. Whereas setting the AVCaptureDevice.ExposureMode to continuousAutoExposure, when there are brighter and lighter objects on the digicam display screen, the lighter half within the digicam display screen will get overexposed.

These are the photographs I am speaking about.
Once I show a brighter picture (on this case, stackoverflow’s web site) on the display screen, it adjusts the publicity.
Nonetheless, once I show a darker picture (on this case, apple’s doc) on the display screen, the white-ish wall and my white desk get overexposed.

enter image description here

enter image description here

That is the code for configuring the digicam publicity.

import AVFoundation

class CameraManager {
    
    static let shared = CameraManager()
    let captureDevice = AVCaptureDevice.default(for: .video)
    
    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 {
            completion(false)
            return
        }
        
        if captureDevice.isSmoothAutoFocusSupported, !captureDevice.isSmoothAutoFocusEnabled { captureDevice.isSmoothAutoFocusEnabled = true }
        
        if captureDevice.isFocusPointOfInterestSupported, captureDevice.isFocusModeSupported(focusMode) {
            captureDevice.focusMode = focusMode
            if let level = level { captureDevice.focusPointOfInterest = level }
        }
        
        if captureDevice.isExposurePointOfInterestSupported, captureDevice.isExposureModeSupported(exposureMode) {
            captureDevice.exposureMode = exposureMode
            if let level = level { captureDevice.exposurePointOfInterest = level }
            
            print("exposureMode: (captureDevice.exposureMode.rawValue)") // -> 2
            print("targetBias: (captureDevice.exposureTargetBias)") // -> 0.0
            print("minExposureTargetBias: (captureDevice.minExposureTargetBias)") // -> -8.0
            print("maxExposureTargetBias: (captureDevice.maxExposureTargetBias)") // -> 8.0
        }
        
        if captureDevice.isWhiteBalanceModeSupported(.continuousAutoWhiteBalance) {
            captureDevice.whiteBalanceMode = .continuousAutoWhiteBalance
        }
        
        captureDevice.isSubjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange
        captureDevice.unlockForConfiguration()
        completion(true)
    }
}

Then I name the setFocus operate within the digicam’s view controller

func setContinuousAutoFocusAndExposure() {
    let heart: CGPoint = CGPoint(x: liveCameraView.hkView.bounds.width / 2, y: liveCameraView.hkView.bounds.top / 2)

    CameraManager.shared.setFocus(with: .continuousAutoFocus, with: .continuousAutoExposure, at: nil, monitorSubjectAreaChange: false, completion: { [weak self] success in
        guard let self = self, success else { return }
        self.liveCameraView.pointOfInterestView.showPointOfInterest(at: heart, hideViewAfterAnimation: true)
    })
}

I’ve heart fixed within the setContinuousAutoFocusAndExposure operate, however that’s solely used for the view animation, and I present nil for the focus.

Only for data, however the iPhone default digicam app’s video mode present’s one thing like this. Each the wall and the desk will not be overexposed.

So, if you recognize why this occurs any code or technique I ought to check out, or information me to the proper course, please let me know….

enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments