As a general rule, the cameras make the photos in landscape or landscape, that is, if you take the photo in portrait or portrait, the resulting photos will be rotated 90 degrees. In this case, the camera software must fill in the Exif data with the orientation in which the photo should be viewed.
Keep in mind that the following solution depends on the manufacturer of the software / device of the camera, so it will work in most cases, but it is not a 100% secure solution, although it always works for me.
ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotateImage(bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotateImage(bitmap, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotateImage(bitmap, 270);
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
break;
}
And the method to rotate the image
public static Bitmap rotateImage(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
matrix, true);
}
I hope that you solve your problem or that this is what you expected.
Greetings.