title: Android Camera Preview Size issue
body: <p>My app opens the camera using surface holder. Camera opens with a default preview size. On certain devices the default preview size captures more image than is actually visible on the screen. Inorder to avoid this, I started setting the preview size myself. Criterion is to select the preview size from the available list of sizes, which is closest to the width of the screen. </p>
  
  <p>This works well most of the time. But often I stumble upon few devices which doesn't like the preview size I selected. </p>
  
  <p>1) Nexus 4 didn't capture the image for one of the preview sizes I selected.
  2) Samsung S 4 gives band of lines(noise) along the  captured images.</p>
  
  <p>So I wanted to understand if I am doing anything against the standard. Here are my questions :- </p>
  
  <p>1) I am using surface holder to open the camera. Is there any other way I can use the camera hardware in my app. </p>
  
  <p>2) I am selecting the preview size from the list of available sizes. Are there any specific which I should look for before selecting any size ?. Logic for selecting the size is mentioned below :- </p>
  
  <pre><code>private Camera.Size getBestPreviewSize(int width, int height)
      {
          List&lt;Size&gt; sizes = camera.getParameters().getSupportedPreviewSizes();
          if (sizes == null) return null;
  
          Size optimalSize = null;
          double minDiff = Double.MAX_VALUE;
  
          int targetHeight = height;
          int targetWidth = width;
  
          int minWidthDiff = 0;
          if (optimalSize == null) {
              minDiff = Double.MAX_VALUE;
              for (Size size : sizes) {
                  if (Math.abs(size.width - targetWidth) &lt; minDiff) {
                      if(size.width &gt; width) {
                          if (minWidthDiff == 0) {
                              minWidthDiff = size.width - width;
                              optimalSize = size;
                          }
                          else if (Math.abs(size.width - targetWidth) &lt; minWidthDiff) {
                              minWidthDiff = size.width - width;
                              optimalSize = size;
  
                          }   
                          minDiff = Math.abs(size.width - targetWidth);
                       }
                  }
              }
          }
  
          if (optimalSize == null) {
              minDiff = Double.MAX_VALUE;
              for (Size size : sizes) {
                  if (Math.abs(size.height - targetHeight) &lt; minDiff) {
                      optimalSize = size;
                      minDiff = Math.abs(size.height - targetHeight);
                  }
              }
          }
          return optimalSize;
      }
  </code></pre>
  
  <p>Any directions on this will really help.</p>
  
  <p>Thanks !!
  Gagan</p>