2017-02-23 75 views
0

我需要的圖像設置爲我的圖像視圖爲什麼畢加索沒有下載圖像?

爲此,我用畢加索庫

這裏是方法,我是如何做到這

File image = new File("file:" + path); 
    Picasso.with(context) 
      .load(image) 
      .placeholder(R.drawable.progress_animation) 
      .error(R.drawable.image_error_404) 
      .into(iv); 

,也是我嘗試同樣沒有前綴file:像這裏

File image = new File(path); 
    Picasso.with(context) 
      .load(image) 
      .placeholder(R.drawable.progress_animation) 
      .error(R.drawable.image_error_404) 
      .into(iv); 

但所有的時間我像從.error()

沒有與file:前綴的路徑 - 「文件:/storage/emulated/0/Android/data/com.fittingroom.newtimezone/files/default/AvatarPackage/DEFAULT_MY_AVATAR/pose1.jpeg」

有是路徑不用其他file:前綴 - 「/storage/emulated/0/Android/data/com.fittingroom.newtimezone/files/default/AvatarPackage/DEFAULT_MY_AVATAR/pose1.jpeg」

反正我沒有結果

爲什麼畢加索不想設置我的形象

我做錯了什麼?

+1

是否'圖像。 exists()'return'true'或'false'?您是否嘗試添加[全局偵聽器](http://stackoverflow.com/a/31608813/115145)以獲取觸發錯誤響應的異常? – CommonsWare

+0

@CommonsWare好的,謝謝我現在我明白了什麼原因 - OOM,圖像太大......但奇怪的是,爲什麼畢加索沒有處理這種情況...因爲例如Glade沒有遇到這樣的錯誤。 ..好吧,這是否意味着我需要調整圖像大小或者我可以添加一些參數? –

+0

AFAIK,畢加索應根據目標'ImageView'的大小來調整大小。還有一些手動選項(例如'.resize()')。 – CommonsWare

回答

0

感謝@CommonsWare我解決我的問題,這樣的方式

.fit() 
.centerInside() 

這裏是我的執行

File image = new File(path); 

    Picasso picasso = new Picasso.Builder(context) 
      .listener(new Picasso.Listener() { 
     @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { 
      Logger.logError("ERROR Download image: ", exception, context); 
     } 
    }).build(); 

    picasso 
      .load(image) 
      .fit() 
      .centerInside() 
      .placeholder(R.drawable.progress_animation) 
      .error(R.drawable.image_error_404) 
      .into(iv, new Callback() { 
       @Override public void onSuccess() { 
        Logger.logGeneral("image downloaded"); 
       } 

       @Override public void onError() { 
        Logger.logGeneral("onError image downloaded"); 
       } 
      }); 
+0

我想知道你使用的是什麼「記錄器」?鏈接將不勝感激。 – AnixPasBesoin

+0

@AnixPasBesoin它只是我自己的實現,沒有什麼特別的 –

0

你的路徑前綴是不正確的:使用file:///代替file:

+0

不,它不起作用 –