Camera API: Cross device issues

后端 未结 3 1851
野趣味
野趣味 2021-02-07 13:30

I\'m developing a camera app basically as part of a messaging app to attach images etc. The app needs to work for >= SDK 2.2 and:

I can\'t use the defau

3条回答
  •  长发绾君心
    2021-02-07 13:37

    I suspect your problem is at a couple different levels.

    Sensor Mount

    First, the camera sensor is mounted different on every device. Google has boiler plate code for getting that orientation and setting the correct rotational value to correct it here and it is good down to API 8.

    AR Correction

    The second issue is obviously that the preview frames aren't the same aspect ratio as the screen. You can use this post to solve that. The surfaceview dimensions have no relation to the best preview size, those values do not have to match - in fact, that your AR is messed up proves that they don't match.

    Preview Frame Size != Picture Size

    Finally, when you take a picture using takePicture, the size of the picture is completely independent of the size of your preview frame. Use the following to query and set the preview frame size: setPreviewSize() / getSupportedPreviewSizes()

    Use the following to query and set the picture size (from takePicture()): getSupportedPictureSizes() / setPictureSize()

    Some devices you may get lucky on and the defaults for pictures and preview frames will be the same. This is not the case on all devices.

    Finally, if you want to display the taken picture, you may need to do AR correction on it as well if it's not the same size as your SurfaceView. Alternatively you could draw it to an ImageView and use ScaleType.CENTER_INSIDE to preserve the aspect ratio.

提交回复
热议问题