I'm currently working on Androids Camera 2 API and my current problem is, that I cannot set the "CONTROL_AE_EXPOSURE_COMPENSATION".
My code:
-1.0 < exposureAdjustment <1.0
public void setExposure(double exposureAdjustment) {
Range<Integer> range1 = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
int minExposure = range1.getLower();
int maxExposure = range1.getUpper();
float newCalculatedValue = 0;
if (exposureAdjustment >= 0) {
newCalculatedValue = (float) (minExposure * exposureAdjustment);
} else {
newCalculatedValue = (float) (maxExposure * -1 * exposureAdjustment);
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue);
}
Unfortunately it doesn't work.
I've found a solution, which works for me. Whereby the exposureAdjustment
parameter is between -1 to +1.
public void setExposure(double exposureAdjustment) {
Range<Integer> range1 = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
int minExposure = range1.getLower();
int maxExposure = range1.getUpper();
if (minExposure != 0 || maxExposure != 0) {
float newCalculatedValue = 0;
if (exposureAdjustment >= 0) {
newCalculatedValue = (float) (minExposure * exposureAdjustment);
} else {
newCalculatedValue = (float) (maxExposure * -1 * exposureAdjustment);
}
if (mPreviewRequestBuilder != null) {
try {
CaptureRequest captureRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(captureRequest, camera2FocusMeteringManager.mCaptureCallbackListener, mBackgroundHandler);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue);
mCaptureSession.capture(captureRequest, camera2FocusMeteringManager.mCaptureCallbackListener, mBackgroundHandler);
} catch (CameraAccessException e) {
}
}
}
}
Where I build a new CaptureRequest
via my mPreviewRequestBuilder
(A builder for capture requests) for each exposure adjustment.
Here you can find a full Camera2 example.