What is the Camera2 API Equivalent of setDisplayOrientation()?

后端 未结 4 1900
走了就别回头了
走了就别回头了 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.
    0 讨论(0)
  • 2020-12-24 13:28

    use the formula below to get device rotation.

    private int getOrientation(int rotation) {
        return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
    }
    

    SensorOrientation is a field assigned from

    characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) 
    

    Solution suggested by google engineer: yaraki

    https://github.com/googlesamples/android-Camera2Basic/issues/24

    0 讨论(0)
  • 2020-12-24 13:28

    use this CaptureRequest JPEG_ORIENTATION to set your display orientation

    captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, 90)

    0 讨论(0)
  • 2020-12-24 13:29

    As you've noticed, this is supposed to "just work" for SurfaceView on the camera2 API.

    As such, there's no equivalent of setDisplayOrientation().

    We haven't heard of this issue before now, so a few questions:

    1. Do you have your app locked to landscape, or are you allowing orientation changes?
    2. Do you handle your own orientation changes, or are you having the framework tear down and restart your app when orientation changes?
    3. Do you trigger any sort of re-layout when the 180-degree rotation occurs, for example to adjust where the shutter button is?
    0 讨论(0)
提交回复
热议问题