Android10中使用图像Uri旋转Picasso图像存在问题。
创始人
2024-08-20 09:00:56
0

在Android 10中,无法直接访问应用程序之外的公共存储的图像文件。因此,必须先将图像文件复制到应用程序内部存储中,然后再使用Picasso加载该图像。同时,为了正确旋转图像,需要使用ExifInterface获取图像的方向,并将其应用于Picasso。以下是解决该问题的代码示例:

String filePath = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues).toString();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
   // Copy the image to the app's internal storage
   ContentResolver resolver = getContext().getContentResolver();
   try (InputStream is = resolver.openInputStream(uri)) {
       FileOutputStream os = getContext().openFileOutput("temp_image", Context.MODE_PRIVATE);
       FileUtils.copy(is, os);
   }

   // Load the image with Picasso and apply the correct rotation
   File file = new File(getContext().getFilesDir(), "temp_image");
   ExifInterface exif = new ExifInterface(file.getPath());
   int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

   Picasso.get()
           .load(file)
           .rotate(getRotationForImage(orientation))
           .into(imageView);
} else {
   Picasso.get()
           .load(uri)
           .into(imageView);
}

// Helper method to get the correct rotation angle
private static float getRotationForImage(int orientation) {
   float rotate = 0;
   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;
   }
   return rotate;
}

相关内容

热门资讯

wepoker破解版内购!aa... wepoker破解版内购!aapoker怎么设置提高好牌几率(透视)器-一直了解真的是有挂1、aap...
大菠萝免费辅助器!约局吧开挂(... 大菠萝免费辅助器!约局吧开挂(透视)神器-一贯了解真的是有挂小薇(辅助器软件下载)致您一封信;亲爱大...
wepoker辅助器软件下载!... wepoker辅助器软件下载!wepoker免费脚本咨询(透视)脚本-总是必备是真的挂1、wepok...
hhpoker怎么破解!wep... hhpoker怎么破解!wepoker私人局辅助器怎么用(透视)器-果然解谜真的有挂1、玩家可以在w...
hhpoker怎么破解!wep... hhpoker怎么破解!wepoker破解器有用吗(透视)攻略-本来了解是真的挂暗藏猫腻,小编详细说...
wepoker网页版透视方法!... wepoker网页版透视方法!aapoker怎么提高中牌率(透视)攻略-切实专业真的是有挂1、进入游...
wepokerplus开挂!h... wepokerplus开挂!hhpoker软件可以玩吗(透视)脚本-其实普及是有挂一、hhpoker...
菠萝辅助器免费版的特点!hhp... 菠萝辅助器免费版的特点!hhpoker是真的还是假的(透视)脚本-都是必备是有挂1、菠萝辅助器免费版...
约局吧德州透视!wepoker... 约局吧德州透视!wepoker透视app下载(透视)脚本-切实曝光有挂1、该软件可以轻松地帮助玩家将...
德扑圈透视!wepoker有透... 德扑圈透视!wepoker有透视底牌吗(透视)app-本来开挂存在有挂1)wepoker有透视底牌吗...