Camera2basic应用程序,在Android 6.0 LGG3中有非常暗的预览

时间:2016-07-21 00:36:57

标签: android android-6.0-marshmallow android-camera2

新的API,也许只在LG G3上,似乎有些变化。

我正在使用the sample code

在我的nexus 4上,代码运行完美,但在LGG3上更新到Android 6.0却没有。有什么想法吗?

我玩了设置,但没有运气,这在Nexus 4上仍能正常工作:

mPreviewRequestBuilder.set(CaptureRequest.BLACK_LEVEL_LOCK, false);


mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_LOCK, false);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_AUTO);


mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_ANTIBANDING_MODE, CaptureRequest.CONTROL_AE_ANTIBANDING_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 0);
//mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range.create(1000,1000));
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, 0);


mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_MODE, CaptureRequest.CONTROL_MODE_AUTO);


mPreviewRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT,
        CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
        CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

3 个答案:

答案 0 :(得分:4)

Camera2 API的FPS范围似乎使用了旧版Camera API的另一个尺度。因此,如果您正在接收支持的预览fps范围(0,30000),则应将值设置为1000:

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range.create(0, 30));

尝试这是否有帮助,因为它有助于使用较旧的Camera API。

答案 1 :(得分:2)

我找到了适合我的解决方案。解决方案是设置设备支持的FPS范围。

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

获取范围的函数:

private Range<Integer> getRange() {
    CameraCharacteristics 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;
}

更新:其他设置(如果有人对此感兴趣)

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE, CameraMetadata.STATISTICS_FACE_DETECT_MODE_SIMPLE);

答案 2 :(得分:0)

设置正确的CONTROL_AE_TARGET_FPS_RANGE是关键。

没有什么理由可以解决这个问题。 正如@Anton Malyshev所说,某些设备会为您提供CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES乘以1000.因此,在设置CONTROL_AE_TARGET_FPS_RANGE时,您必须将其除以1000。

我想到的另一个原因是,根据分辨率,自动曝光会因更高的FPS而失败。所以我做的一个简单的解决方法是将较低的范围设置为0.

例如,如果CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES有24000:24000, 然后在将较低值分割并设置为0之后,范围将为0:24