Why is ExifInterface.TAG_ORIENTATION always 0?

时间:2015-10-06 08:56:23

标签: android orientation exif

I want to take a picture and then display it in an imageView. But the problem is the orientation because sometimes my image is being displayed the wrong way.

All I found here was to get the information of the orientation out of the ExifInterface like this:

   ExifInterface exif = new ExifInterface(uri.getPath());
    int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
    int rotationInDegrees = exifToDegrees(rotation);
    Matrix matrix = new Matrix();
    if (rotation != 0f) {
matrix.preRotate(rotationInDegrees);
}
    Bitmap adjustedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);

with

     private static int exifToDegrees(int exifOrientation) {        
         if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {  return 90;  } 
         else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180;  } 
         else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {   return 270;  }            
         return 0;    
      }

I got this from [Android get Orientation of a camera Bitmap? And rotate back -90 degrees

the problem is that I always get an orientation of 0. And the image is always displayed in landscapeview. Can anyone help?

0 个答案:

没有答案