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:
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.
Remove the below condition and initialize the default camera globally and also remove the for loop.
if(mCameraId == null) {
mCameraId = cameraId;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With