I'm trying to get pictures using front camera (selfie) and back camera and save it to an imageview. When I tried to take a picture using the front camera (selfie) the image is getting flipped upside down (vertical) and when using the back camera, the image is getting flipped horizontally.
I'm trying to detect the camera usage using "camInfo.facing ==(Camera.CameraInfo.CAMERA_FACING_FRONT" and "camInfo.facing ==(Camera.CameraInfo.CAMERA_FACING_BACK" but only "camInfo.facing ==(Camera.CameraInfo.CAMERA_FACING_BACK" is working. I hope I can give some rotation to get it to work.
Dont know how to proceed. Help much appreciable.
compileSdkVersion 28
defaultConfig {
applicationId "com.austurn.keikonew.keiko"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
try {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Uri uri = photoURI;
Bitmap myImg = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
Matrix matrix = new Matrix();
int width = myImg.getWidth();
int height=myImg.getHeight();
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.CameraInfo camInfo = new Camera.CameraInfo();
if (camInfo.facing ==(Camera.CameraInfo.CAMERA_FACING_FRONT)) {
matrix.postRotate(90);
Toast.makeText(this.getActivity(), "Front camera", Toast.LENGTH_LONG).show();
}
if (camInfo.facing ==(Camera.CameraInfo.CAMERA_FACING_BACK)) {
Toast.makeText(this.getActivity(), "back camera", Toast.LENGTH_LONG).show();
float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);
matrix.postConcat(matrixMirrorY);
matrix.postRotate(270);
}
Bitmap bitPicFinal = Bitmap.createBitmap(myImg, 0, 0, width, height,matrix, true);
myImg.recycle();
int desWidth;
int desHeight;
desWidth = bitPicFinal.getWidth();
desHeight = desWidth;
Bitmap croppedBitmap = Bitmap.createBitmap(bitPicFinal, 0,bitPicFinal.getHeight() / 2 - bitPicFinal.getWidth() / 2,desWidth, desHeight);
croppedBitmap = Bitmap.createScaledBitmap(croppedBitmap, 528, 528, true);
camview.setImageBitmap(croppedBitmap);
}
}catch(Exception e){
Toast.makeText("Something went wrong", Toast.LENGTH_LONG).show();
}
}
}