title: Camera setDisplayOrientation() in Portrait Mode Breaks Aspect Ratio
body: <p>I am trying to get camera previews to work properly in portrait mode, where the activity itself is allowed to change orientation normally (i.e., not be locked to landscape).</p>
  
  <p>The use of <code>setDisplayOrientation()</code> seriously breaks the behavior of the previews, though.</p>
  
  <p>This can be demonstrated by Google's own ApiDemos. The first image is based on the <code>CameraPreview</code> from the <code>android-17</code> edition of the <code>ApiDemos</code> sample project, where the only change I made was to remove <code>android:orientation="landscape"</code> from this activity's entry in the manifest. The following image is a screenshot of what appears on the display of a Nexus 4, running Android 4.2, with the camera pointed at a 8.5" square of paper:</p>
  
  <p><img src="https://i.stack.imgur.com/YmY3P.png" alt="Nexus 4 ApiDemos Preview, Portrait Mode"></p>
  
  <p>What is not obvious from that preview is that it is rotated 90 degrees. The sock-clad feet that you see on the far right of the image were actually below the square.</p>
  
  <p>The solution for this, at least for landscape mode, is to use <code>setDisplayOrientation()</code>. But, if you modify the <code>Preview</code> inner class of <code>CameraPreview</code> to have <code>mCamera.setDisplayOrientation(90);</code>, you get this:</p>
  
  <p><img src="https://i.stack.imgur.com/or9lQ.png" alt="Nexus 4 ApiDemos Preview, Portrait Mode, with setDisplayOrientation(90)"></p>
  
  <p>Notably, the square is no longer square.</p>
  
  <p>This uses the same <code>SurfaceView</code> size as before. I have reproduced this scenario with some other code, outside of <code>ApiDemos</code>, and I get the same behavior with <code>TextureView</code> in that code.</p>
  
  <p>I thought briefly that the issue might be that <code>getSupportedPreviewSizes()</code> might return different values based upon <code>setDisplayOrientation()</code>, but a quick test suggests that this is not the case.</p>
  
  <p>Anyone have any idea how to get <code>setDisplayOrientation()</code> to work in portrait mode without wrecking the aspect ratio of the imagery pushed over to the preview?</p>
  
  <p>Thanks!</p>