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

相关内容

热门资讯

截至目前!樱花之盛低价挂,we... 截至目前!樱花之盛低价挂,wepoker有透视功能吗,办法教程(有挂教学)-哔哩哔哩在进入wepok...
透视实锤!德普之星私人局透视,... 透视实锤!德普之星私人局透视,德普之星私人局辅助器(透视)真是是有挂(有挂详细)-哔哩哔哩一、德普之...
随着!心悦辅助出售平台,小程序... 随着!心悦辅助出售平台,小程序雀神免费脚本,模板教程(有挂方针)-哔哩哔哩1、打开软件启动之后找到中...
透视游戏!德扑圈透视挂,德普之... 透视游戏!德扑圈透视挂,德普之星透视辅助软件激活码(透视)总是是有挂(有挂解密)-哔哩哔哩1、实时德...
据公告内容!熊猫免费脚本辅助工... 据公告内容!熊猫免费脚本辅助工具,hhpoker透视工具,操作教程(有挂工具)-哔哩哔哩1、不需要A...
透视实锤!德普之星怎么开辅助,... 透视实锤!德普之星怎么开辅助,德普之星私人局辅助器(透视)总是真的是有挂(有挂头条)-哔哩哔哩1、点...
透视代打!德普之星透视,德普之... 透视代打!德普之星透视,德普之星透视辅助(透视)确实存在有挂(有挂教程)-哔哩哔哩1、德普之星透视辅...
目前!衢州都莱破解器,微乐小程... 目前!衢州都莱破解器,微乐小程序游戏辅助器脚本官网,烘培教程(有挂详情)-哔哩哔哩;1、这是跨平台的...
近日!微友辅助神器下载,微信小... 近日!微友辅助神器下载,微信小程序微乐辅助器免费下载,步骤教程(真是有挂)-哔哩哔哩1、微信小程序微...
透视科技!德普之星私人局辅助器... 透视科技!德普之星私人局辅助器,德扑圈有透视吗(透视)切实是真的挂(有挂细节)-哔哩哔哩1、进入游戏...