Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, front and back camera Orientation , Landscape

In my camera app, you can switch between the front and back camera. When I take picture with the back camera the picture is the same like the preview shows. But when I switch to the front camera, the picture is mirrorrd.I think it has something to do that front and back camera is in landscape mode. I have tried almost every given answers on SO.

It would really help if someone could point me in the right directions.

like image 395
Maikel Bollemeijer Avatar asked Nov 30 '11 20:11

Maikel Bollemeijer


People also ask

How do I change the camera orientation on my Android?

The expression deviceOrientationDegrees * sign + 360 converts device rotation from counterclockwise to clockwise for back-facing cameras (for example, converting 270 degrees counterclockwise to 90 degrees clockwise).

What is camera orientation?

The orientation of a Camera Station defines the position of and the pointing direction of the camera at the time of exposure of a photograph. Orientation can also refer to the process of determining the orientation of one or more Camera Stations.

Why does an image captured using camera intent gets rotated on some devices on Android?

Answer: Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees. In this case, the camera software should populate the Exif data with the orientation that the photo should be viewed in.

What is a camera preview screen?

PreviewView is a subclass of FrameLayout . To display the camera feed, it uses either a SurfaceView or TextureView , provides a preview surface to the camera when it's ready, tries to keep it valid as long as the camera is using it, and when released prematurely, provides a new surface if the camera is still in use.


1 Answers

I found the answer , doing mCamera.setDisplayOrientationa(int degrees); did not help. I had to mirror the generated bitmap in order to get the result I wanted. I used the Matrix method to a achieve this .

float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
Matrix matrix = new Matrix();
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);

matrix.postConcat(matrixMirrorY);

image = Bitmap.createBitmap(mBitmap, 0, 0, frame.getWidth(), frame.getHeight(), matrix, true)
like image 58
Maikel Bollemeijer Avatar answered Nov 06 '22 10:11

Maikel Bollemeijer