Android 如何在通过库打开图像时旋转图像?

Android 如何在通过库打开图像时旋转图像?,android,android-camera,Android,Android Camera,通过我的相机应用程序拍摄,并通过Galerry打开图像: 我的代码打开: Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(dt.FileName); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity

通过我的相机应用程序拍摄,并通过Galerry打开图像: 我的代码打开:

Intent intent = new Intent();                           
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(dt.FileName);
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);

通过标准摄像机拍摄,并通过Galerry打开图像:

我检查原始图像是否相同。
使用相同的标准照相机打开图像库时如何旋转图像?

使用此代码更改图像方向

          ExifInterface exif = new ExifInterface(filepath);
          int exifOrientation = exif.getAttributeInt(
          ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);

          int rotate = 0;

          switch (exifOrientation) 
        {
          case ExifInterface.ORIENTATION_ROTATE_90:
          rotate = 90;
          break; 

         case ExifInterface.ORIENTATION_ROTATE_180:
         rotate = 180;
         break;

         case ExifInterface.ORIENTATION_ROTATE_270:
         rotate = 270;
         break;
         }

           if (rotate != 0) 
        {
          int w = bitmap.getWidth();
          int h = bitmap.getHeight();


          Matrix mtx = new Matrix();
          mtx.preRotate(rotate);

         bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
         bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
       }

必须另存为其他文件?如果使用矩阵,我只能在我的控件上设置,但我调用android的android.content.Intent.ACTION\u视图。您可以更改图像的方向并将其存储,然后显示该图像。图像与原始图像是否不同?