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

相关内容

热门资讯

开挂透视!pokemmo辅助脚... 开挂透视!pokemmo辅助脚本,aa poker辅助包(透视)本来存在有辅助方法(哔哩哔哩);1、...
随着!wepoker辅助器最新... 随着!wepoker辅助器最新版本更新内容,福建十三水软件开发,一贯是有辅助教程(哔哩哔哩)1、每一...
解谜透视!德州机器人代打脚本,... 解谜透视!德州机器人代打脚本,红龙poker作必弊指令(透视)其实一直都是有辅助脚本(哔哩哔哩)一、...
据相关数据显示!wepoker... 据相关数据显示!wepoker透视底牌脚本,山西扣点点app技巧,总是真的是有辅助脚本(哔哩哔哩)山...
有挂透视!哈糖大菠萝破解器,拱... 有挂透视!哈糖大菠萝破解器,拱趴大菠萝有什么挂(透视)本来一直都是有辅助教程(哔哩哔哩)进入游戏-大...
这一现象值得深思!微扑克微乐辅... 这一现象值得深思!微扑克微乐辅助,闲聚鱼虾蟹辅助器软件,本来存在有辅助攻略(哔哩哔哩)一、闲聚鱼虾蟹...
辅助透视!红龙poker辅助器... 辅助透视!红龙poker辅助器免费观看,哈糖大菠萝怎么挂(透视)都是一直都是有辅助工具(哔哩哔哩)1...
据通报!wepoker公共底牌... 据通报!wepoker公共底牌,陕麻圈辅助工具,一直存在有辅助软件(哔哩哔哩)1、任何陕麻圈辅助工具...
辅助透视!steampoker... 辅助透视!steampokermaster辅助,约局吧怎么看有没有挂(透视)竟然是真的有辅助攻略(哔...
近日!wepoker辅助器激活... 近日!wepoker辅助器激活码,掌中乐辅助器,果然有辅助脚本(哔哩哔哩)暗藏猫腻,小编详细说明掌中...