Eric Chuang
Eric Chuang

Reputation: 1027

How can I change the whiteBalanceGains value?

I am getting the error:

- whiteBalanceGains contain an out-of-range value. Red, green, and blue gains must be in the [1, maxWhiteBalanceGain] range

How can I determine maxWhiteBalanceGain range?

AVCaptureDevice *device =
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureWhiteBalanceTemperatureAndTintValues temperatureAndTint = {
    .temperature = 8000,
    .tint = 146,
};

[device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint];

[device setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:[device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint] completionHandler:^(CMTime syncTime) {

 }];

Upvotes: 2

Views: 1957

Answers (1)

Robert Fogash
Robert Fogash

Reputation: 176

rom apple developer doc

"Note though that some temperature and tint combinations yield out-of-range device RGB values that will cause an exception to be thrown if passed directly to setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:completionHandler:. Be sure to check that the red, green, and blue gain values are within the range of [1.0 - maxWhiteBalanceGain]."

So, first, you have to get the white balance gains

AVCaptureWhiteBalanceGains wbGains = [device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint]

Than, check if wbGains.redGain, wbGains.blueGain, wbGains.greenGain in range of [1 ... maxWhiteBalanceGain].

maxWhiteBalanceGain is a property of the AVCaptureDevice object.

Upvotes: 4

Related Questions