What is the Camera2 API Equivalent of setDisplayOrientation()?

后端 未结 4 1909
走了就别回头了
走了就别回头了 2020-12-24 12:35

With android.hardware.Camera, in order to have the camera output appropriately track the device movement, we need to hook up an OrientationEventListener

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 13:14

    There is none.

    It does not "just work" if display orientation is swapped compared to sensor orientation (on most devices this is the case in portrait mode) because you have to set an aspect ratio < 1 for your preview surface that camera2 cannot map to a fitting output size. Solution:

    • In the first API, you use camera.setDisplayOrientation()
    • In camera2, I could not find a way to use a SurfaceHolder, but only a SurfaceTexture with surfaceTexture.setTransform(android.graphics.Matrix) call in portrait mode.

提交回复
热议问题