Android camera preview is dark

心已入冬 提交于 2019-11-28 07:46:25

From my experiments, scene-mode setting can change the preview (unlike ISO or exposure-compensation, which both work for captured pictures). Don't use auto. Try scene-mode-values=night or scene-mode=dusk-dawn.

The problem with scenes is that the supported values are not standardized across devices. But some kind of night is usually present.

Praveena

There appears to be a bug with certain cameras reporting the supported preview FPS range incorrectly. You can identify the offending devices by those that return the same value for min and max when calling

getPreviewFpsRange (int[] range)

In my case I saw this issue with devices that reported (15000, 15000) and (30000, 30000), but not with devices where the values were different, like (7000, 30000).

The best solution I could find was to identify the supported FPS range that had different values for min and max, and set that:

Camera.Parameters params = camera.getParameters();
final int[] previewFpsRange = new int[2];
params.getPreviewFpsRange(previewFpsRange);
if (previewFpsRange[0] == previewFpsRange[1]) {
    final List<int[]> supportedFpsRanges = params.getSupportedPreviewFpsRange();
    for (int[] range : supportedFpsRanges) {
        if (range[0] != range[1]) {
            params.setPreviewFpsRange(range[0], range[1]);
            break;
        }
    }
}
camera.setParameters(params);

This works because the ranges reported seem to only have 1 item with the actual range. Eg:

BLU Vivo XL:

preview-fps-range=30000,30000
preview-fps-range-values=(15000,15000),(20000,20000),(24000,24000),(5000,30000),(30000,30000)

Pixel:

preview-fps-range=7000,30000
preview-fps-range-values=(15000,15000),(24000,24000),(7000,30000),(30000,30000)

A more robust approach would be to set the min and max by comparing all those available.

In addition to the previous answers, this can happen with Camera2 if you are doing

createCaptureRequest(CameraDevice.TEMPLATE_RECORD)

change to

createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)

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