How rotate image when open image by Gallery?

随声附和 提交于 2021-01-29 08:31:31

问题


Capture by My Camera App and Open image by Galerry: My code open:

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);

enter image description here

Capture by Standard Camera and Open image by Galerry: enter image description here

I check Original Image is the same. How rotate image when open image by Gallery the same Standard Camera?


回答1:


Use this code to change the image orientation

          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);
       }


来源:https://stackoverflow.com/questions/22905768/how-rotate-image-when-open-image-by-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!