1. 程式人生 > >android的Picasso和Glide載入本地圖片的區別

android的Picasso和Glide載入本地圖片的區別

最近專案中有用到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路徑}傳遞{@codenull}不會觸發任何請求,但會設定一個  
   *佔位符,如果指定。  
   *   
   * @see #load(Uri)  
   * @see #load(File)  
   * @see #load(int
   * @throws IllegalArgumentException if {@code path}為空或空白字串。  
   * /  public RequestCreator load(String path) {   
if (path == null) {      
             returnnew RequestCreator(this, null, 0);    
            }    
if (path.trim().length() == 0) {     
thrownew IllegalArgumentException("Path must not be empty.");   
     }   
return load(Uri.parse(path));  
}