title: Android camera preview: 1:1 aspect ratio, how?
body: <p>Hi
  I am trying to use the camera to capture an image in one of my application. What is special is that I need a square preview area (and picture in the end). I tried defining the size of both picture and preview to 1:1 pixel ratios, but nothing seams to work. No matter what I does the picture looks "squashed" on a square. </p>
  
  <p>Anyone who has any idea about how to resolve this? </p>
  
  <p>code:</p>
  
  <pre><code>public class AddFromCameraActivity extends Activity implements SurfaceHolder.Callback {
  private Camera mCamera;
  private Parameters mParameters; 
  private SurfaceView mCameraPreview;
  private SurfaceHolder mSurfaceHolder; 
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.addimagefromcameramain); 
      initialise(); 
      //Testing area
      mCamera = Camera.open(); 
      mParameters = mCamera.getParameters(); 
      mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); 
      mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); 
      mParameters.setJpegQuality(50); 
      mParameters.setJpegThumbnailQuality(50); 
      mParameters.setPictureSize(1024, 1024);
      //mParameters.setPreviewFormat(ImageFormat.JPEG); 
      mParameters.setJpegThumbnailSize(256, 256); 
      mParameters.setPreviewSize(500, 500); 
      mCamera.setParameters(mParameters);
  }
  private void initialise()
  {
      mCameraPreview = (SurfaceView)findViewById(R.id.cameraSurfaceView); 
      mSurfaceHolder = mCameraPreview.getHolder(); 
      mSurfaceHolder.addCallback(this); 
      mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
      mSurfaceHolder.setFixedSize(500, 500); 
  }
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width,
          int height) {
  
  }
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      try {
          mCamera.setPreviewDisplay(mSurfaceHolder);
          mCamera.startPreview(); 
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } 
  }
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
      mCamera.stopPreview(); 
      mCamera.release(); 
  }
  @Override
  public void onPause()
  {
      mCamera.release(); 
  }
  }
  </code></pre>
  
  <p>thanks</p>