Camera display doesn't maintain aspect ratio/seems skewed
<p>I'm running into an issue with camera input in Android. After searching over the internet for half a day I'm not getting any further.</p>

<p>Wat I want to achieve at this stage is correctly displaying the current camera input. Nothing more and nothing less for now. When holding the device in landscape mode, all seems fine. However as soon as I switch the device to portrait the display seems to be horizontally scaled in order to match the width of the screen on the device. </p>

<p>In order to clarify this issue a bit more, I've attached two photographs:</p>

<ul>
<li><a href="http://i.stack.imgur.com/9FSMs.jpg" rel="nofollow">Landscape (looks correct)</a></li>
<li><a href="http://i.stack.imgur.com/ECeH6.jpg" rel="nofollow">Portrait (looks incorrect)</a></li>
</ul>

<p>It seems like this issue also occurs with the camera example from the API examples, but it doesn't seem to occur when I use the camera application from my device. So clearly something else is happening there. </p>

<p>The code that I'm using is based on examples that can be found over the internet and has no modifications:</p>

<pre><code>class Preview extends SurfaceView implements SurfaceHolder.Callback {
    SurfaceHolder mHolder;
    Camera mCamera;

    Preview(Context context) {
        super(context);
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        mCamera.stopPreview();
        mCamera = null;
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }
}
</code></pre>

<p>The API examples make use of a method "getOptimalPreviewSize(...)" which sounds like the method I need, but that does not change anything. I left it out here in order to be as brief as possible.</p>

<p>Am I missing something obvious or is this the expected behavior?</p>

<p>Hopefully someone can point me in the correct direction.</p>

<p>Thanks in advance!</p>

<p>Paul</p>
