I have an application which uses the camera of an android device. The activity which takes the picture can not be rotated, it is displayed only in portrait. On most devices this code works fine:
int degrees = 0;
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int result;
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (cameraInfo.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (cameraInfo.orientation - degrees + 360) % 360;
} camera.setDisplayOrientation(result);
but on a device (DMTECH 725H, a 7" tablet, with only a front camera) the preview is displayed upside down. Any ideas how to fix it?
The reason of wrong camera rotation can be in unusual orientation of sensor, as mentioned in this support issue. And you also should use camera2
package instead of android.hardware.Camera
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With