我需要從我的服務器下載圖像並將此圖像加載到imageview中。所以我有一個問題 - 我可以下載圖像到內存中並將其設置爲ImageView,而不保存在SD卡/本地存儲上?或者我必須下載到一些文件存儲?如果可能,請給我舉例。如何在Java,Android下載ImageView ImageView?
0
A
回答
-1
例如代碼爲here。您可以使用BitmapFactory來實現自己的目標:
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
2
同樣的問題被問這樣你就可以搜索,
InputStream in = null;
try
{
URL url = new URL("URL FOR IMAGE");
URLConnection urlConn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.connect();
in = httpConn.getInputStream();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
bmpimg = BitmapFactory.decodeStream(in);
ImageView iv = "MY IMAGEVIEW";
iv.setImageBitmap(bmimg);
0
這可以幫助你。
Bitmap bmImg;
void downloadFile(String fileUrl){
URL myFileUrl =null;
try {
myFileUrl= new URL(fileUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
來源:http://en.androidwiki.com/wiki/Loading_images_from_a_remote_server
看到這個太
http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/
的相關問題
- 1. Android ImageView ImageView
- 2. android imageView
- 3. android - ViewHolder ImageView隨機加載
- 4. 在Android中設置ImageView中的ImageView
- 5. 如何在imageview上設置imageview?
- 6. 如何讓Android ImageView逐漸下載圖像
- 7. Android的 - 在ImageView的
- 8. 動態ImageView在android
- 9. 在Android ImageView中加載圖片
- 10. 在Android中加載Imageview的進度條
- 11. 在android中加載圖像imageview
- 12. 只要ImageView被按下就顯示ImageView
- 13. android studio在imageview下方製作一個textView,如果imageview沒有圖像可見
- 14. ImageView內容從另一個ImageView加載到另一ImageView
- 15. Android ImageView Loop
- 16. Android ImageView縮小
- 17. android imageView scale
- 18. Android imageview longpress hint
- 19. imageview android 2.1
- 20. Android - ImageView縮放
- 21. Android ImageView問題
- 22. Android ImageView問題
- 23. Android廣場imageview
- 24. Android WebView或ImageView?
- 25. Android ImageView setImageBitmap
- 26. android,imageview stretch
- 27. Android ImageView - 16:9
- 28. ImageView getLocationtOnScreen android
- 29. Android ImageView鏈接
- 30. android imageview wrap_content
可能重複[如何從URL中的應用程序下載圖像](http://stackoverflow.com/questions/ 7763841 /如何下載圖像從應用程序中的網址) –