所有垂直方向的图像仅在某些设备上奇怪地自动旋转

All vertical oriented images are strangely autorotated only on some devices

我有一个应用程序可以从相机或画廊拍摄照片并在图像视图中显示结果。

我只获取content provider的图片,使用这个缩放功能

public Bitmap scaleim(Bitmap bitmap) {
       ...
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, resizedWidth, resizedHeight, false);
        return scaledBitmap;
    }

在我的 android 5 设备上一切正常,现在我已经在我的 Android 7 朋友设备上测试了同一个应用程序,并且 每张图片都是垂直的oriented 自动旋转到水平方向。 这看起来真的很奇怪,我不知道是什么导致了这个问题。

问题不在于缩放,但捕获的图像根据 hardware.Before 开始缩放时的工作方式不同,应该根据合适的设备进行旋转。 这是以下代码:

  Matrix matrix = new Matrix();
  matrix.postRotate(getImageOrientation(url));
  Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
  bitmap.getHeight(), matrix, true)

public static int getImageOrientation(String imagePath){
     int rotate = 0;
     try {

         File imageFile = new File(imagePath);
         ExifInterface exif = new ExifInterface(
                 imageFile.getAbsolutePath());
         int orientation = exif.getAttributeInt(
                 ExifInterface.TAG_ORIENTATION,
                 ExifInterface.ORIENTATION_NORMAL);

         switch (orientation) {
         case ExifInterface.ORIENTATION_ROTATE_270:
             rotate = 270;
             break;
         case ExifInterface.ORIENTATION_ROTATE_180:
             rotate = 180;
             break;
         case ExifInterface.ORIENTATION_ROTATE_90:
             rotate = 90;
             break;
         }
     } catch (IOException e) {
         e.printStackTrace();
     }
    return rotate;
 }