通过图库打开图像时如何旋转图像? [英] How rotate image when open image by Gallery?

查看:87
本文介绍了通过图库打开图像时如何旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过我的相机"应用捕获和由Galerry打开图像:我的代码打开:

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

通过标准相机捕获,通过Galerry打开图像:

Capture by Standard Camera and Open image by Galerry:

我检查原始图像是否相同.在同一图库的标准相机中打开图像时如何旋转图像?

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

推荐答案

使用此代码更改图像方向

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

这篇关于通过图库打开图像时如何旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆