Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera is stretching in portrait mode

I am trying to put the camera in a surfaceView in portrait orientation on android phone. I used http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html to put the camera in the surfaceView. However the camera is rotated 90 degrees, so I tried doing setDisplayOrientation(90) to fix it, but this squashes the image (it Probably isn't resizing the surfaceView properly??). How can I make it so the camera is not squished?

like image 867
user1154920 Avatar asked Mar 06 '12 19:03

user1154920


2 Answers

You need to resize the image according to the rotation. See here for an example.

like image 96
John J Smith Avatar answered Oct 20 '22 12:10

John J Smith


If you were using Android API demos, you need to modify OnLayout() function.

Basically the Android API demo, sets the preview size in according to the aspect ratio so that the preview image is squished and display in center of screen with small size in portrait mode.

Even if we set-up screen orientation to Portrait mode, preview width and height are not changed. That's why the preview image was squished.

like image 2
Teddydino Avatar answered Oct 20 '22 11:10

Teddydino