Start a new topic

Camera View flipped on M6.0 Nexus 5X

Camera View flipped on M6.0 Nexus 5X

There's a issue with the SDK on Android when running on a the new LG Nexus 5X.
The Nexus 5X has a rare camera setup where the camera sensor is physically mounted reverse landscape.

Theefore the default behaviour of the camera API in android results in the image being flipped
This affects many apps, not just the Wikitude SDK.

Thanksfully the solution is simple however it requires a tweak to code in the SDK where you are setting up the Android Camera API

You need to setDeviceOrientation correctly taking into account the sensor orientation which is available from the orientation property of the CameraInfo object.
There's a sample of how to fix this issue on the Android docs.

Esentially you need to combine the display orientation in degrees with the sensor orientation.


public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) {
     android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
     android.hardware.Camera.getCameraInfo(cameraId, info);
     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 (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;


Thx Rob for the case and the detailed description. Unfortunately the suggested solution will not work for us, as we are using the camera differently. We will address the problem in on the following maintenance releases for the Android SDK. 

I see ok, no problem, I look forward to it.

The just updated SDK (both Native 1.2 and JavaScript 5.1) now contain support for the Nexus 5X rotated camera.

Thanks Philipp, much appreciated, I'll update and test later.
Login or Signup to post a comment