picasso 显示本地图片

感慨下,一开始搜索问题的时候,发现文章都没有说如何显示本地图片,都在说一些如何加载网络图片,本地图片直接放url 什么的,几乎找的文章都一样。很是郁闷,也有可能是我关键词有问题;关键时候还得看源码


1.问题

一般我们获取到的完整路径:
/storage/emulated/0/Android/data/xxxx.jpg,
picasso.load(url) 直接将这个路径进行load 是显示不了的。


2.解决方案

如果上述的url,请在前面加上 “file://” 的前缀
//picasso 显示本地图片需要 如下格式
String realPath = “file://”+new File(event.photo).getPath();

2.1下面是源码的一些说明:


/ **
   *使用指定的路径启动图像请求。这是一个方便的呼叫方法
   * {@link #load(Uri)}。
   * <p>
   *此路径可能是远程URL,文件资源(前缀为{@code file:}),内容资源
   *(前缀为{@code content:})或Android资源(以{@code为前缀)
   * android.resource:}。
   * <p>
   *作为{@code路径}传递{@code null}不会触发任何请求,但会设置一个
   *占位符,如果指定。
   *
   * @see #load(Uri)
   * @see #load(File)
   * @see #load(int)
   * @throws IllegalArgumentException if {@code path}为空或空白字符串。
   * /
  public RequestCreator load(String path) {
    if (path == null) {
      return new RequestCreator(this, null, 0);
    }
    if (path.trim().length() == 0) {
      throw new IllegalArgumentException("Path must not be empty.");
    }
    return load(Uri.parse(path));
  }

2.2 Picasso Load image from filesystem

http://stackoverflow.com/questions/23681177/picasso-load-image-from-filesystem/23681332

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值