嗨,我是新的Android初學者。我想從URL中的imageView插入圖像,但每當它從imageView中的URL加載時,第二次它應該插入沒有互聯網意味着它將被存儲在緩存中。從URL加載圖像到imageView以及緩存
2
A
回答
6
對於這一點,你可以用畢加索庫 您可以從畢加索圖書館網站上下載它只是把這個jar文件到libs文件夾中。它將管理Image的所有屬性。 http://square.github.io/picasso/
String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);
+0
thanx第三方是最好的方法 –
2
您可以使用Picasso
庫。
使用Picasso
,其優點是
- 處理ImageView的回收和適配器下載取消。
- 複雜的圖像轉換與最小的內存使用。
- 自動內存和磁盤緩存。
從Url
Picasso.with(context).load(url).into(imageView);
加載Image
請參閱此鏈接API:Picasso
1
我建議這樣做畢加索庫。 here是畢加索圖書館的詳細文檔。
例如:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
,或者您可以使用凌空的ImageLoader的的。 here你可以找到Volley的圖像加載文檔。
例如:
// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
mImageView.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
mImageView.setImageResource(R.drawable.image_load_error);
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
如果您使用的凌空抽射。那麼你必須手動緩存圖像。畢加索將默認緩存圖像。
1
可以使用滑翔https://github.com/bumptech/glide
Glide.with(this).load("imageURl").into(imageView);
相關問題
- 1. 存儲圖像到緩存,以避免從URL中的tableview頻繁加載
- 2. 加載圖像到ImageView的
- 3. 從其他緩存圖像加載緩存圖像
- 4. Android:爲imageView緩存圖像
- 5. 圖像在加載到iframe後無法從緩存中加載
- 6. 從firebase和緩存加載圖像swift3
- 7. 從URL和緩存中逐一加載和顯示圖像
- 8. 安卓:保存從庫圖像,然後加載到ImageView的
- 9. 畢加索圖像加載以前緩存圖像
- 10. 從sdcard緩慢加載圖像到gridview
- 11. ImageView找不到圖像URL
- 12. 從imageview中加載圖像的功能
- 13. 從URL加載.svg圖像
- 14. Android從URL加載圖像
- 15. ImageSwitcher從url加載圖像
- 16. 圖像未從URL加載到Mvx.MvxImageView
- 17. 從URL加載圖像到ListView
- 18. 預加載和緩存圖像,然後從緩存中刪除舊圖像
- 19. 將MYSQL加載到Imageview的圖像
- 20. 使用picasso將圖像加載到imageview
- 21. 無法將圖像加載到ImageView
- 22. 將圖像加載到ImageView中Android
- 23. ImageView中未加載圖像
- 24. Android - 在顯示進度的同時將圖像從URL加載到ImageView(不保存圖像)
- 25. android,我如何從緩存中加載/加載圖像?
- 26. android -universal圖像加載器無法從緩存加載
- 27. 圖像加載程序位圖緩存
- 28. 在ImageView中刷新圖像緩存
- 29. 如何從android中的URL將圖像加載到動態創建的imageview中?
- 30. 將4mb圖像從URL添加到android studio的imageVIew中
所以你有什麼迄今所做? – Shahzeb
使用壁畫,它是Facebook的圖像加載庫,似乎對我很好https://github.com/facebook/fresco –
如果您正在查找diskcache,請簽出此文件http://stackoverflow.com/a/32516598/1939564和這如果你正在尋找內存緩存http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html –