2017-04-10 56 views
4

Android應用程序允許用戶從他們的手機庫中選擇一張照片,並將URI保存到領域。然後我檢索這些信息並使用Picasso將它加載到圖像視圖中。出於某種原因,圖像未加載。Android無法使用Picasso從URI加載圖像

URI是這樣的:

content://com.android.providers.media.documents/document/image%3A333180 

我使用mCategory.icon = imageURI.toString()它保存到的境界,然後當我加載它:

Picasso.with(getContext()) 
       .load(Uri.parse(mCategory.icon)) // mCategory.icon is a string 
       .resize(200, 200) 
       .error(R.drawable.mountain) // default image to load 
       .into(viewHolder.categoryIcon); 
+0

該Uri是無效的圖像路徑Uri。 – Enzokie

回答

3

你得到的URI是ContentProvider URI以顯示它畢加索你試圖做到這一點:

File file = new File(Uri.parse(mCategory.icon)); 
    Picasso.with(getContext()) 
      .load(file) 
      .resize(200, 200) 
      .error(R.drawable.mountain) 
      .into(viewHolder.categoryIcon); 

PS:雖然你可以轉換喲烏爾ContentProveder路徑Absolute路徑仍然是更好,如果你因爲從文件畢加索支持負載不..

+0

你檢查了你的文件嗎?檢查文件是否使用file.exists() –

+0

正確加載我解決了我的pbm感謝您的回覆.... + 1 –

1

使用setLoggingEnabled(true)畢加索檢查日誌,如果有任何錯誤消息。

0

提及的URI包含冒號的編碼值:即%3A。

要麼重命名源,要麼嘗試Glide或某個其他庫來達到目的。

相關問題