Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Camera in Portrait Orientation

Tags:

android

I'm trying to develop an app which uses the Camera. So far it's been working well, except that I'm unable to force the orientation to be "portrait". It seems to work well if I force all activities to "landscape", because the camera preview seems to fit in landscape.

Is there anyway to use the Camera in portrait mode?

like image 221
paperclip Avatar asked Sep 11 '10 14:09

paperclip


People also ask

What is camera portrait mode?

Portrait mode is a phone camera feature that keeps objects in the foreground focused while blurring the background.

Is it better to shoot in landscape or portrait?

Shooting a portrait will make the main subject appear closer, allowing you to fill the frame as much as possible. Shooting in landscape format would result in a wider depth of field, letting you play with foreground and background.

What are the two types of camera orientation?

What is Camera Orientation? There are two kinds of camera orientations, Vertical or Portrait, and Horizontal or Landscape. By simply rotating your camera and changing the direction, you can achieve different looks on the images.


2 Answers

Android devices v2.2 and above contain and API to rotate the display to portrait. Devices below 2.2 are landscape only. Your best bet is to detect if the device is 2.2 and rotate 90 degrees. Fall back on landscape for devices under 2.2. The good news is most Android devices are on 2.2 and above.

Check out my answer here for more info:

Camera is wrong unless keyboard is open

like image 123
Ryan Reeves Avatar answered Sep 24 '22 17:09

Ryan Reeves


public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open();

Parameters params = mCamera.getParameters();

if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
{
params.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
}

try
{
mCamera.setPreviewDisplay(holder);
}
catch (IOException exception)
{
mCamera.release();
mCamera = null;
}

}
like image 43
VIGNESH.SRINIVASAGAN Avatar answered Sep 24 '22 17:09

VIGNESH.SRINIVASAGAN