Java – use the Camera2 API to rotate the preview direction in landscape mode clockwise
I wrote a camera application using the Camera2 API
But I don't see the same problem in the potrait model
What is the cause of this problem in landscape mode?
This is the screen rotation code:
private static final SparseIntArray ORIENTATIONS = new SparseIntArray(); static { ORIENTATIONS.append(Surface.ROTATION_0,90); ORIENTATIONS.append(Surface.ROTATION_90,0); ORIENTATIONS.append(Surface.ROTATION_180,270); ORIENTATIONS.append(Surface.ROTATION_270,180); }
Solution
I have the same problem – this is because the default camera sensor orientation may be 90 degrees or 270 degrees, depending on your device In order to render the camera output to the screen, considerable preprocessing is involved in setting the camera output
The method setupcameraoutputs (int width, int height) in the official Google example shows how to do this( https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java )Basically, it checks the camera's sensor orientation and determines whether the preview area needs to be rotated