本文介绍了如何在Android的Camera2 API中设置"CONTROL_AE_EXPOSURE_COMPENSATION"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Androids Camera 2 API,目前的问题是我无法设置"CONTROL_AE_EXPOSURE_COMPENSATION".

I'm currently working on Androids Camera 2 API and my current problem is, that I cannot set the "CONTROL_AE_EXPOSURE_COMPENSATION".

我的代码:

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.

推荐答案

我找到了一个对我有用的解决方案.因此,exposureAdjustment参数在-1到+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) {
            }
        }
    }
}

我通过mPreviewRequestBuilder(捕获请求的构建器)为每次曝光调整构建新的CaptureRequest.

Where I build a new CaptureRequest via my mPreviewRequestBuilder (A builder for capture requests) for each exposure adjustment.

在这里,您可以找到完整的Camera2示例.

Here you can find a full Camera2 example.

这篇关于如何在Android的Camera2 API中设置"CONTROL_AE_EXPOSURE_COMPENSATION"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:46