With android.hardware.Camera
, in order to have the camera output appropriately track the device movement, we need to hook up an OrientationEventListener
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:
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
use this CaptureRequest JPEG_ORIENTATION to set your display orientation
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, 90)
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: