I am rendering camera preview
on GLSurfaceView
everything works fine but camera preview
show upside down on some device specially on Nexus 5X . I have checked this solution Android - Camera preview is sideways
. This is my code for handling orientation problem
private void setCameraDisplayOrientation() {
Constants.debugLog(TAG_DEBUG, "setCameraDisplayOrientation");
Constants.debugLog(TAG, "setCameraDisplayOrientation ");
if (camera == null) {
Constants.debugLog(TAG + " Owncamera", "setCameraDisplayOrientation - camera null");
return;
}
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(currentCameraId, info);
WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int rotation = winManager.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 (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
this.cameraOrientation = 2;
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
this.cameraOrientation = 1;
}
Constants.debugLog(TAG_DEBUG, "result: " + result + " this.cameraOrientation == " + this.cameraOrientation);
Constants.debugLog(TAG, "result: " + result + " this.cameraOrientation == " + this.cameraOrientation);
//Log.e("camera_orient", "res: "+ result);
camera.setDisplayOrientation(result);
}
From the Camera.CameraInfo info
class, i can get orientation
. For maximum device the values i get on portrait mode
is "for front camera = 270, back camera = 90
"" but on Nexus 5X
it provide camera orientation
270,270 for both front & back camera. Beside on other devices my camera provide result
value 90 for both front and back camera in portrait mode but for Nexus 5x
front camera 90 back camera 270. I have also tried by setting value fixed 90 on camera.setDisplayOrientation(90);
Nexus 5X device but don't work
How to handle this problem so that all device camera orientation will be same and i won't get any rotated image ??