getSupportedPictureSize() returns a value which is not actually supported by Nexus4

前端 未结 3 1138
孤街浪徒
孤街浪徒 2020-12-15 00:51

I have extended a SurfaceView for displaying the camera feed for a very simple camera application. To find the optimal preview size for each device, I used this sample code

3条回答
  •  没有蜡笔的小新
    2020-12-15 01:19

    I have the same problem on an LG Lucid (model number VS840 4G). Basically, getSupportedPictureSizes() returns these sizes:

    Size        Aspect Ratio
    2560x1920   (1.3333333333333333)
    3072x1728   (1.7777777777777777)
    2048x1536   (1.3333333333333333)
    2304x1296   (1.7777777777777777)
    1536x864    (1.7777777777777777)
    1280x960    (1.3333333333333333)
    640x480     (1.3333333333333333)
    

    If we call setPictureSize() with any of the sizes with a 1.7 aspect ratio, the camera hardware throws no errors, but it returns an image that is distorted:

    sample of distorted result from LG Lucid, showing what appears to be a pixel buffer interpreted with the wrong stride

    I tried a number of techniques to get the camera driver to admit this size was not really supported, including checking the result of getPictureSize() and getSupportedPictureFormats() after calling setParameters(). I couldn't find anything that gave away this behavior.

    To work around this, we now mimic the behavior of the stock Camera app: we attempt to find a "preferred" size from the getSupportedPictureSizes() list before falling back to selecting the largest (as computed by width * height). Since the preferred sizes all have an aspect ratio of 1.333 (4:3), this works around the issue on this device.

    See the Camera app source where it sets the value (line 111) and the hardcoded sizes it prefers (line 63) for the exact implementation.

提交回复
热议问题