最近项目中有用到Picasso和Glide来加载本地图片,发现有些区别
图片路径:
String framePicPath="/storage/sdcard1/Android/data/com.example.lshapp.shortvideodemo
/cache/taorecorder_video/8fb7387865234e9cbf3983d0d1dcfe2d_output.jpg";
Glide加载的时候:
Gradle中的依赖:
compile 'com.github.bumptech.glide:glide:3.7.0'
代码://其中的load()参数可以直接为路径字符串,文件,uri。我这里用的是路径字符串。可以正常显示本地图片
Glide.with(EditVideoActivity.this).load(framePicPath)
.error(R.drawable.jc_play_normal).into(imageviewvideo);
Picasso加载的时候:
Gradle中的依赖:
compile files('libs/picasso-2.4.0.jar')
代码://看源码发现其中的load()参数也可以直接为路径字符串,文件,uri。我这里用的是路径字符串。不可以正常显示本地图片
Picasso.with(EditVideoActivity.this).load(framePicPath)
.error(R.drawable.jc_play_normal).into(imageviewvideo);
//这里用的文件形式就可以正常显示了。不知道为啥?
Picasso.with(EditVideoActivity.this).load("file://" + framePicPath)
.error(R.drawable.jc_play_normal).into(imageviewvideo);
查看Picasso源码:
/ **
*使用指定的路径启动图像请求。这是一个方便的呼叫方法
* {
@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));
}