Save Photographs in Horizontal Mode ExifInterface class

0

I have an application on android, when I take the picture, and every time I show it in an imageView, the image always changes its orientation. Is there a way to store it in the orientation I want?

Can you take a picture in android studio and save it as a horizontal image? Even if it is taken as Vertical or Horizontal?

Using the ExitInterface class or something like that?

Thanks and regards.

    
asked by Devix 21.02.2017 в 05:54
source

1 answer

0

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.

    
answered by 22.02.2017 в 10:13