Android camera preview is dark

前端 未结 3 2133
长情又很酷
长情又很酷 2020-12-08 23:41

I am trying to create a custom camera app. I followed the Android Developer example from here with minor tweaks. However, my camera preview turns out to be rather dark. On t

相关标签:
3条回答
  • 2020-12-08 23:52

    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)
    

    UPDATE: I have also begun to see a dark preview on some newer Pixel devices and this happens if you don't set the fps in the capture request or if you set the fps to something that the device can't handle BUT not on Samsung devices like the Note 10 and S10

    0 讨论(0)
  • 2020-12-08 23:55

    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.

    0 讨论(0)
  • 2020-12-09 00:05

    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.

    0 讨论(0)
提交回复
热议问题