iPad Camera Orientation in QuickReport Template

587
2
Jump to solution
03-27-2019 09:14 AM
ChristopherEby2
New Contributor III

When I use the AppStudio Quick Report template on my iPad, try to attach an image from the camera, and switch from the back camera to the front camera, the camera video preview is rotated 180 degrees (is upside down). However, if I capture an image from the front camera, the preview shows it oriented correctly. I've tested my 6th Gen iPad (Model A1954) with both the QuickReport template for Appstudio versions 3.2 and 3.3 beta and am seeing this on both. The front camera rotation is correct in the Survey123 included in AppStudio 3.3. Is there a workaround for this?

0 Kudos
1 Solution

Accepted Solutions
ChristopherEby2
New Contributor III

 We logged this as a bug (Case #02294905) but I found my own workaround. I pulled code from the latest Survey123 Template and added it to the code in the QuickReport Template to fix the issue. I made these changes to the CameraComponent.qml file:

1. First, I copied in a property to detect if the device is running iOS

      readonly property bool isIOS: Qt.platform.os === "ios"

2. Then I copied in a function to detect 

      function isIPhone() {

         if (Qt.platform.os === "ios" && AppFramework.systemInformation.hasOwnProperty("unixMachine")) {

            if (AppFramework.systemInformation.unixMachine.match(/^iPhone/)) {

               return true;

            }

         }

         return false;

      }

3. Finally, I modified the switchCamera() function to include the orientation logic from Survey123:

      function switchCamera() {

         if (QtMultimedia.availableCameras.length > 0) {

            var cameraIndex = 0;

            for (var i = 0; i < QtMultimedia.availableCameras.length; i++) {

               if (QtMultimedia.availableCameras[i].deviceId === camera.deviceId) {

                  cameraIndex = i;

                  break;

               }

            }

         cameraIndex = (cameraIndex + 1) % QtMultimedia.availableCameras.length;

         if(QtMultimedia.availableCameras.length>1) isBackCamera = !isBackCamera

         camera.stop();

         camera.deviceId = QtMultimedia.availableCameras[cameraIndex].deviceId;

         switch(cameraFlashMode){

         case 0:

            camera.flash.mode = Camera.FlashAuto;

            flash_icon.source = "./assets/flash_auto.png"

            break;

         case 1:

            camera.flash.mode = Camera.FlashOn;

            flash_icon.source = "./assets/flash_on.png"

            break;

         case 2:

            camera.flash.mode = Camera.FlashOff;

            flash_icon.source = "./assets/flash_off.png"

            break;

         }

         cameraCurrentZoomScale = 1.0

         //Code pulled from Survey123 to fix iOS orrientation issue

         if(iOS) {

            videoOutPut.autoOrientation = false;

            videoOutPut.orientation = Qt.binding(function(){

               var currentOrientation = parseInt(Screen.orientation, 10);

               if (camera.position === Camera.FrontFace) {

                  if (isIPhone()) {

                     return ((camera.orientation + 180) % 360) * -1;

                  }

               else {

                  if (currentOrientation === 1 || currentOrientation === 0) {

                     return ((camera.orientation + 180) % 360) * -1;

                  } else if (currentOrientation === 2) {

                     return (((camera.orientation + 180) % 360) * -1) + 90;

                  } else if (currentOrientation === 4) {

                     return (camera.orientation + 180) % 360;

                  } else {

                     return (((camera.orientation + 180) % 360) * -1) - 90;

                  }

               }

            } else {

               return camera.orientation;

            }

         });

      }

      //End of code pulled from Survey123 to fix iOS orrientation issue

      camera.start();

   }

}

This solved my issue!

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi Chris,

Thank you for reporting this issue to our GeoNet community. Could you please log an issue to Esri Support team and we will try to fix it.

Tina 

0 Kudos
ChristopherEby2
New Contributor III

 We logged this as a bug (Case #02294905) but I found my own workaround. I pulled code from the latest Survey123 Template and added it to the code in the QuickReport Template to fix the issue. I made these changes to the CameraComponent.qml file:

1. First, I copied in a property to detect if the device is running iOS

      readonly property bool isIOS: Qt.platform.os === "ios"

2. Then I copied in a function to detect 

      function isIPhone() {

         if (Qt.platform.os === "ios" && AppFramework.systemInformation.hasOwnProperty("unixMachine")) {

            if (AppFramework.systemInformation.unixMachine.match(/^iPhone/)) {

               return true;

            }

         }

         return false;

      }

3. Finally, I modified the switchCamera() function to include the orientation logic from Survey123:

      function switchCamera() {

         if (QtMultimedia.availableCameras.length > 0) {

            var cameraIndex = 0;

            for (var i = 0; i < QtMultimedia.availableCameras.length; i++) {

               if (QtMultimedia.availableCameras[i].deviceId === camera.deviceId) {

                  cameraIndex = i;

                  break;

               }

            }

         cameraIndex = (cameraIndex + 1) % QtMultimedia.availableCameras.length;

         if(QtMultimedia.availableCameras.length>1) isBackCamera = !isBackCamera

         camera.stop();

         camera.deviceId = QtMultimedia.availableCameras[cameraIndex].deviceId;

         switch(cameraFlashMode){

         case 0:

            camera.flash.mode = Camera.FlashAuto;

            flash_icon.source = "./assets/flash_auto.png"

            break;

         case 1:

            camera.flash.mode = Camera.FlashOn;

            flash_icon.source = "./assets/flash_on.png"

            break;

         case 2:

            camera.flash.mode = Camera.FlashOff;

            flash_icon.source = "./assets/flash_off.png"

            break;

         }

         cameraCurrentZoomScale = 1.0

         //Code pulled from Survey123 to fix iOS orrientation issue

         if(iOS) {

            videoOutPut.autoOrientation = false;

            videoOutPut.orientation = Qt.binding(function(){

               var currentOrientation = parseInt(Screen.orientation, 10);

               if (camera.position === Camera.FrontFace) {

                  if (isIPhone()) {

                     return ((camera.orientation + 180) % 360) * -1;

                  }

               else {

                  if (currentOrientation === 1 || currentOrientation === 0) {

                     return ((camera.orientation + 180) % 360) * -1;

                  } else if (currentOrientation === 2) {

                     return (((camera.orientation + 180) % 360) * -1) + 90;

                  } else if (currentOrientation === 4) {

                     return (camera.orientation + 180) % 360;

                  } else {

                     return (((camera.orientation + 180) % 360) * -1) - 90;

                  }

               }

            } else {

               return camera.orientation;

            }

         });

      }

      //End of code pulled from Survey123 to fix iOS orrientation issue

      camera.start();

   }

}

This solved my issue!

0 Kudos