2

I am using commonware's camera sample to try and create an android app that takes a picture. The preview shows the camera rotated 90 degrees and I've corrected that by applying:

camera.setDisplayOrientation(90);

However, the images are still saved rotated 90 degrees the other way. How can I adjust this so that when the images are saved, they're saved in the same "aspect" as that of the viewer?

Please advise, TIA

joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
Christopher Johnson
  • 2,629
  • 7
  • 39
  • 70

1 Answers1

0

According to this post , this happens only in some devices and it depends on the manufacturer.

I managed to workaround this issue by detecting the orientation angle of the device and apply the rotation accordingly, like this:

            ExifInterface exitInterface = new ExifInterface(imagePath);

            int orientation = exitInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
            int degree = 0;

            switch (orientation){
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
            }

Then I rotate my bitmap using a custom method:

    public static Bitmap rotateImage(Bitmap src, float degree) 
{
        // create new matrix
        Matrix matrix = new Matrix();
        // setup rotation degree
        matrix.postRotate(degree);
        Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
        return bmp;
}
Community
  • 1
  • 1
joao2fast4u
  • 6,868
  • 5
  • 28
  • 42