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

相关内容

热门资讯

WPK俱乐部!红龙扑克技巧辅助... WPK俱乐部!红龙扑克技巧辅助器ai,德普之星透视辅助插件,一直是有ai辅助器课程1、德普之星透视辅...
WPK四人!AApoker脚本... WPK四人!AApoker脚本透视ai,poker红龙辅助,一贯是真的有ai透视积累1、下载好pok...
WPK四人!wpk软件开挂ai... WPK四人!wpk软件开挂ai,约局吧能不能开挂,原来真的有ai开挂操作运约局吧能不能开挂辅助工具,...
WPK安装!德扑之星攻略辅助器... 您好,拱趴大菠萝作弊方法这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多...
WPK透视版!WPKapp透视... WPK透视版!WPKapp透视挂ai,德州透视是真的假的,竟然真的是有ai透视挂指引所有人都在同一条...
WPK透视!WePoKer软件... WPK透视!WePoKer软件透视挂ai,红龙poker辅助工具,都是存在有ai透视挂手册1、每一步...
WPK辅助!aapoker工具... 您好,大菠萝免费辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩...
WPK靠谱!菠萝智星德州脚本开... WPK靠谱!菠萝智星德州脚本开挂ai,AApoker下载,本来是有ai开挂攻略1、AApoker下载...
WPK辅助!WePoKer教程... WPK辅助!WePoKer教程辅助ai,大菠萝789辅助器下载,一贯是真的有ai辅助项目1、操作简单...
WPK透视!智星菠萝德州app... WPK透视!智星菠萝德州app透视ai,约局吧开挂,切实存在有ai透视方针1、首先打开约局吧开挂辅助...