版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/android_freshman/article/details/66476102
感慨下,一开始搜索问题的时候,发现文章都没有说如何显示本地图片,都在说一些如何加载网络图片,本地图片直接放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