How to set the ''CONTROL_AE_EXPOSURE_COMPENSATION'' in Camera2 API on Android?

陌路散爱 提交于 2019-12-11 01:04:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42852933/how-to-set-the-control-ae-exposure-compensation-in-camera2-api-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!