Using the camera in portrait orientation

I am trying to develop an application that uses a camera. So far, this works well, except that I can't get the orientation to be a "portrait." It seems to work well if I make all the actions "landscape" because the camera preview seems to fit the landscape.

Can I use the camera in portrait mode?

+6
source share
3 answers

Android devices v2.2 and higher contain an API for rotating the display to a portrait. Devices below 2.2 are terrain only. It is best to determine if the device is 2.2 and rotates 90 degrees. Return to the landscape for devices under 2.2. The good news is that most Android devices are on 2.2 and up.

See my answer here for more information:

The camera is wrong if the keyboard is not open

+6
source
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; } } 
+3
source

edit: I was in the middle of developing Adobe AIR for Android when I answered this question and, looking back, I realized that this question does not apply to Adobe AIR.

Adobe says:

On devices that can change the screen orientation, such as mobile phones, a Video object attached to the camera will only show vertical video in landscape orientation. Thus, mobile applications should use landscape orientation when displaying video and should not automatically rotate.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html

If you really want to use the camera in portrait mode, my suggestion is to rotate the video object.

Here is an example of code that rotates a video object (_video) by an angle in degrees (the source was pulled from another place in stackoverflow):

  var matrix:Matrix = _video.transform.matrix; var rect:Rectangle = _video.getBounds(this); matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2))); matrix.rotate((angle/180)*Math.PI); matrix.translate(rect.left + (rect.width/2), rect.top + (rect.height/2)); _video.transform.matrix = matrix; 
0
source

All Articles