Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera2Basic app front camera takes pic upside down

I have tried Google's android-Camera2Basic sample app. For front camera get works, I have changed some code in Camera2BasicFragment. The changes are as follows.

To switch to front camera I have changed mCameraId = cameraId; to mCameraId = "1"; in setUpCameraOutputs(int width, int height) method.

And added on if condition at end of setUpCameraOutputs(int width, int height) like,

if(mCameraId == null)
    mCameraId = cameraId;

This change shows front camera perfectly but doesn't pick the photo. So I replaced

mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                        mBackgroundHandler);

to

captureStillPicture();

in lockFocus(). Now front camera picks the photo, but it looks upside down.

For ex:

sample image

I don't know what to do now.

My requirement is to capture photo in both cameras using camera2 api. So if I did anything wrong please correct me.

And in some devices this app takes more than one pic on single click.

like image 872
Gunaseelan Avatar asked Aug 31 '17 13:08

Gunaseelan


1 Answers

Remove the below condition and initialize the default camera globally and also remove the for loop.

if(mCameraId == null) {
   mCameraId = cameraId;
}
like image 100
Bill Karwin Avatar answered Sep 27 '22 22:09

Bill Karwin