【问题标题】:android Picasso load image from storageandroid Picasso 从存储中加载图像
【发布时间】:2018-06-27 22:55:05
【问题描述】:

我正在使用 Picasso 从网络和本地存储加载图像

用于从网络加载图像

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

为了从存储中加载图像,我在加载图像的路径之前添加file://

Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);

但是当文件路径有带有文件名的 utf-8 字符时,它不会像 file:///android_asset/۲۰۱٧.png 那样加载图像

知道每次我想使用 picaso 时如何解决它,它必须是字符串路径而不是 UriFile,因为它作为字符串保存在 sqlite 中

【问题讨论】:

  • 我尝试将具有该文件名的图像放在我的资产文件夹中,毕加索将其加载到 ImageView 中没有任何问题。如果重要的话,我使用的是 Picasso 2.5.2。
  • 澄清一下,当我按原样使用路径“file:///android_asset/2010.png”时,Picasso v2.5.2 对我正常工作,没有任何编码(如下面的答案所示)。也许是其他原因导致了问题?

标签: android picasso


【解决方案1】:

试试这个代码:

String url = "file:///android_asset/۲۰۱٧.png";
URLEncoder.encode(url, "UTF-8");
Picasso.with(context).load(url).into(imageView2);

【讨论】:

    【解决方案2】:

    试试看

    URIUtil.encodeQuery(url)
    

    查看问题:

    https://github.com/square/picasso/issues/652

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 2018-07-14
      • 2023-01-29
      • 2017-05-05
      • 2019-10-06
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多