其他分享
首页 > 其他分享> > Android Camera2增加亮度

Android Camera2增加亮度

作者:互联网

我在我的应用程序中使用android camera2拍摄连续图像,这时我使用camera2获得的图像预览亮度与原始相机相比非常暗.我看过this,但答案中没有类似的要求.

我按照建议here尝试在camera2中设置亮度:

Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true.

captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

但它仍然显示预览为暗图像,如下所示.

看到这里的区别:

原装相机:
enter image description here

使用Camera2:
enter image description here

我需要传递的值是什么,作为第二个参数:

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

我保持6,因为正如doc的建议:

For example, if the exposure value (EV) step is 0.333, ‘6’ will mean an exposure compensation of +2 EV; -3 will mean an exposure compensation of -1 EV.

但亮度仍然没有影响..

解决方法:

这里是:

在onConfigured()和unlockFocus()中添加以下代码

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,getRange());

通过使用上面的代码,您将获得更好的预览.但是你拍摄的照片将保持不变.为了获得更好的图片,请在captureStillPicture()中使用相同的以下代码

captureBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getRange());

getRange是:

    private Range<Integer> getRange() {
    CameraCharacteristics chars = null;
    try {
        chars = mCameraManager.getCameraCharacteristics(mCameraId);
        Range<Integer>[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
        Range<Integer> result = null;
        for (Range<Integer> range : ranges) {
            int upper = range.getUpper();
            // 10 - min range upper for my needs
            if (upper >= 10) {
                if (result == null || upper < result.getUpper().intValue()) {
                    result = range;
                }
            }
        }
        if (result == null) {
            result = ranges[0];
        }
        return result;
    } catch (CameraAccessException e) {
        e.printStackTrace();
        return null;
    }
}

标签:android-camera2,android
来源: https://codeday.me/bug/20191001/1840351.html