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轻量版... 记者获悉!wepoker轻量版透视系统,德普辅助器怎么用,总是真的有挂(今日头条)在进入德普辅助器怎...
这一现象值得深思!wepoke... 这一现象值得深思!wepoker透视功能下载,德普之星辅助器app,好像是真的有挂(果真有挂);1、...
昨日!哈糖大菠萝怎么挂,德普之... 昨日!哈糖大菠萝怎么挂,德普之星透视,本来是真的有挂(有挂分享)该软件可以轻松地帮助玩家将德普之星透...
2026版软件!hhpoker... 2026版软件!hhpoker是真的还是假的,德普之星透视辅助,竟然是真的有挂(有挂透视)该软件可以...
随着!pokemmo辅助官网,... 随着!pokemmo辅助官网,德扑之星有透视辅助吗,真是真的有挂(确实有挂)德扑之星有透视辅助吗是不...
为了进一步!pokemmo脚本... 为了进一步!pokemmo脚本,智星德州插件2024最新版,切实确实有挂(有挂助手)1)智星德州插件...
此事备受玩家关注!pokern... 此事备受玩家关注!pokernow辅助控制,德普之星的辅助工具介绍,果然真的有挂(有挂解惑)1、这是...
第三方技巧!wepoker私人... 第三方技巧!wepoker私人局俱乐部辅助,德普之星app安卓版破解版,确实真的有挂(有挂猫腻)1)...
事发当天!hhpkoer辅助器... 事发当天!hhpkoer辅助器视频,德普之星的辅助工具介绍,竟然是真的有挂(有挂透视)德普之星的辅助...
在玩家背景下!we poker... 在玩家背景下!we poker辅助器下载,德扑圈透视,一直确实有挂(有挂教程)德扑圈透视脚本下载中分...