Android Camera2 增加亮度 [英] Android Camera2 increase brightness

查看:96
本文介绍了Android Camera2 增加亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 android camera2 拍摄连续图像,这里当我使用 camera2 时,与原始相机相比,图像预览亮度非常暗.我看到了

使用 Camera2:

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

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

我保留了 6,因为正如文档中的建议:

<块引用>

例如,如果曝光值 (EV) 步长为 0.333,则6"表示曝光补偿为 +2 EV;-3 表示曝光补偿为 -1 EV.

但仍然没有影响亮度..

解决方案

这里是:

onConfigured()unlockFocus()

中添加以下代码

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

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

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

getRange 是:

 私有范围<整数>获取范围(){CameraCharacteristics 字符 = null;尝试 {字符 = mCameraManager.getCameraCharacteristics(mCameraId);Range[] 范围 = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);范围<整数>结果 = 空;for(范围<整数>范围:范围){int upper = range.getUpper();//10 - 满足我需要的分钟范围上限如果(上 >= 10){if (result == null || upper < result.getUpper().intValue()) {结果 = 范围;}}}如果(结果 == 空){结果=范围[0];}返回结果;} catch (CameraAccessException e) {e.printStackTrace();返回空;}}

I am using android camera2 in my application to take continuous images, Here when I use camera2 getting image preview brightness very dark compare to original camera. I seen this but there is no similar requirement in that answer.

I tried to set brightness in camera2 as suggested here:

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);

But it still showing preview as dark image only as shown below.

See the difference here:

Original Camera:

Using Camera2:

And what is the value I need to pass as second parameter in:

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

I kept 6 because as suggested in doc's:

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.

But still no effect in brightness..

解决方案

Here it is:

Add below code in onConfigured() and unlockFocus()

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

By using the above code you will get the better preview. But your captured picture will remain as it is. To get the better picture as well use the same below code in captureStillPicture()

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

getRange is:

    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 增加亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆