5

I would like to get the value of the current gains and change the value of the RGB gains.

In iOS, Apple provides setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:completionHandler.

- (void)setWhiteBalanceGains:(AVCaptureWhiteBalanceGains)gains
{
  NSError *error = nil;
  
  if ( [self.captureDevice lockForConfiguration:&error] ) {
    AVCaptureWhiteBalanceGains normalizedGains = [self normalizedGains:gains];
    [self.captureDevice setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:normalizedGains completionHandler:nil];
    [self.captureDevice unlockForConfiguration];
  }
  else {
    NSLog( @"Could not lock device for configuration: %@", error );
  }
}

- (AVCaptureWhiteBalanceGains)normalizedGains:(AVCaptureWhiteBalanceGains) g
{
  AVCaptureWhiteBalanceGains gains = g;
  gains.redGain = MAX(gains.redGain, 1.0f);
  gains.greenGain = MAX(gains.greenGain, 3.0f);
  gains.blueGain = MAX(gains.blueGain, 18.0f);
  
  return gains;
}

How can we achieve this in android using cameraX?

COLOR_CORRECTION_GAINS

COLOR_CORRECTION_MODE

I have checked in the doc regarding channel control. But how can we change color correction and reset the cameraX preview with the new control?

Balasubramanian
  • 5,274
  • 6
  • 33
  • 62

2 Answers2

1

You can use Camera2Interop:

fun buildPreview() : Preview {
    val builder = Preview.Builder()
    val camera2InterOp = Camera2Interop.Extender(builder)
    camera2InterOp.setCaptureRequestOption(CaptureRequest. COLOR_CORRECTION_MODE, CameraMetadata.COLOR_CORRECTION_MODE_FAST)
    return builder.build()
}
Xi 张熹
  • 10,492
  • 18
  • 58
  • 86
1

Old but still used is the class Camera.Parameters#getWhiteBalance

https://developer.android.com/reference/android/hardware/Camera.Parameters#getWhiteBalance()

Using class Camera.Parameters call getWhiteBalance.

The newer way is to use Capture request https://developer.android.com/reference/android/hardware/camera2/CaptureRequest

Here is the full documentation of Camera2 https://developer.android.com/reference/android/hardware/camera2/package-summary

Drivers Sea
  • 446
  • 2
  • 10