title: Camerainfo.orientation gives wrong answer
body: <p>Android provides <a href="http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29" rel="noreferrer">this code</a> to make a camera preview appear face-up for all camera and screen orientations:</p>
  
  <pre><code>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;
       }
       camera.setDisplayOrientation(result);
   }
  </code></pre>
  
  <p>In the simplest case, when the screen is face-up in portrait (<code>rotation</code> is 0) with a back-facing camera, this reduces to <code>result = info.orientation</code>.  According to the docs, info.orientation is</p>
  
  <blockquote>
    <p>the angle that the camera image needs to be rotated
    clockwise so it shows correctly on the display in its natural
    orientation. It should be 0, 90, 180, or 270.</p>
  </blockquote>
  
  <p>This means that <code>info.orientation</code> should be the amount the raw images from the camera are rotated <em>counter-clockwise</em>.</p>
  
  <p>On a Samsung Galaxy S II's back-facing camera, <code>info.orientation</code> is 90, as expected for back-facing cameras.  However, the raw camera preview is rotated 90 degrees clockwise, not counter-clockwise.  This means that after applying the above code, the preview appears upside-down (180 degrees).  </p>
  
  <p><strong>Why is there a 180 degree discrepancy between the camera's reported orientation and the actual orientation of its raw images?</strong></p>
  
  <p>This exact problem - camera images being 90 degrees clockwise when <code>info.orientation</code> reports 90 - has also been reported in <a href="https://stackoverflow.com/questions/9055460/is-androids-camerainfo-orientation-correctly-documented-incorrectly-implemente">this question</a> and <a href="https://stackoverflow.com/questions/13103070/is-the-setdisplayorientation-sample-code-correct?rq=1">this one</a>.</p>
  
  <p>Also see <a href="https://stackoverflow.com/questions/11135166/android-camera-orientation-phone-gives-false-data">this possibly related question</a>.</p>