title: Camera display / preview in full screen does not maintain aspect ratio - image is skewed, stretched in order to fit on the screen
body: <p>I have developed a small application for displaying camera preview in full screen. I'm using Camera API for this.</p>
  
  <p>This is the activity layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;
  
      &lt;!-- This is the container for the camera preview screen --&gt;
      &lt;FrameLayout android:id="@+id/camera_preview"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When device is in portrait, the display is vertically scaled in order to match the height of device screen - so the aspect ratio is not the same as the one from native camera. These are 2 images which explains better what I'm saying:</p>
  
  <p><img src="https://i.stack.imgur.com/lwWT3.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/Y1kxa.jpg" alt="enter image description here"></p>
  
  <p>The first image is made with native camera device.
  The second image is made with my app, with camera in full screen - the image is skewed, stretched in order to fit on the screen.</p>
  
  <p>I need the camera preview to be full screen, regardless of the preview size given by <code>getSupportedPreviewSizes()</code> mehod and without distortion.
  Is there a way to accomplish this? Is there a way to maintain proper aspect ratio when camera preview is in full screen? I expected this to be done automatically by OS - cropping the image to match the requested resolution while maintaining aspect ratio, but this does not happen.</p>
  
  <p>I've tried to make the <code>SurfaceView</code> larger than the display (following this question: <a href="https://stackoverflow.com/questions/11321251/fitting-a-camera-preview-to-a-surfaceview-larger-than-the-display">Fitting a camera preview to a SurfaceView larger than the display</a>), but is not ok in my case since I'm capture snapshots (6 frames/second) and those are not what user sees on the screen (the frame contains all camera preview even if not all of it is visible on the screen).</p>
  
  <p>I posted here: <a href="https://www.dropbox.com/s/3d52xt8kazynsae/CameraFullScreen.7z?v=0mcn" rel="noreferrer">https://www.dropbox.com/s/3d52xt8kazynsae/CameraFullScreen.7z?v=0mcn</a> the entire project I've made.</p>
  
  <p>Any idea/solution is more than important to me. Thanks a lot.</p>
  
  <p>========================================================================</p>
  
  <p><strong>Update due to ss1271 answer:</strong></p>
  
  <p>I'll analyze a little the resolutions you wrote above for <strong>Samsung Galaxy Ace II</strong>.</p>
  
  <p><strong>I. Screen resolution</strong>: 480x800 - aspect ratio 3:5 = <strong>0,6</strong></p>
  
  <p><strong>II. <code>getSupportedPreviewSizes</code></strong> - I'm almost sure that these values are from back camera. Below are the aspects ratio for these resolutions:</p>
  
  <pre><code>   2560x1920   - 0,75
  
     2560x1536   - 0,60
  
     2048x1536   - 0,75
  
     2048x1232   - 0,60
  
     960x720     - 0,75
  
     640x480     - 0,75
  </code></pre>
  
  <p>So, your method will return a <code>Size</code> corresponding to <strong>2560x1536</strong> or to <strong>2048x1232</strong> - these having the same aspect ratio as screen resolution and using these values will not distort the picture.
  The problem for me is that I cannot use so big resolutions since I capture 6 frames/second and these needs to be saved at a lower resolution.</p>
  
  <p>I'll present below some results from a <strong>Samsung S2</strong> device:</p>
  
  <p><strong>I. Screen resolution</strong>: 480 x 800  - aspect ratio 3:5 = <strong>0,6</strong></p>
  
  <p><strong>II. Back camera</strong><br/>
  a). <code>getSupportedPreviewSizes</code>:</p>
  
  <pre><code>800 / 480   - 480/800 = 0,60
  800 / 450   - 450/800 = 0,56
  720 / 480   - 0,66 
  640 / 480   - 0,75
  352 / 288   - 0,81
  320 / 240   - 0,75
  176 / 144   - 0,81
  </code></pre>
  
  <p>b). Native camera resolutions:</p>
  
  <pre><code>3264 / 2448  - 0,75  - not full screen
  3264 / 1968  - 0,60  - FULL SCREEN (since has the same aspect ratio as device screen)
  2048 / 1536  - 0,75  - not full screen
  2048 / 1232  - 0,60  - FULL SCREEN (same aspect ratio as device screen)
  800 / 480    - 0,60  - FULL SCREEN (same aspect ratio as device screen)
  640 / 480    - 0, 75 - not full screen
  </code></pre>
  
  <p><strong>III. Front camera</strong><br/>
  a). <code>getSupportedPreviewSizes</code>:</p>
  
  <pre><code>640 / 480   - 0,75
  352 / 288   - 0,81
  320 / 240   - 0,75
  176 / 144   - 0,81
  </code></pre>
  
  <p>b). Native camera is not in full screen and I cannot choose a resolution - the option is disabled.</p>
  
  <p>For S2, back camera, I'm wonder why <code>getSupportedPreviewSizes()</code> method do not return the same resolutions as Native camera does or the ones displayed by native camera are the picture sizes ? I'm wonder why I do not have options like 3264 / 1968, 2048 / 1232 given by <code>getSupportedPreviewSizes()</code> method ?
  :
  <img src="https://i.stack.imgur.com/fliSf.jpg" alt="enter image description here"></p>