獲取網絡上的圖像

String imgUrl = http://xxxxxxxxx......jpg;  //定義圖片的網絡位置

URL  url = new URL(imgUrl);                     //建立指向圖片的URL

HttpURLConnection connection = (HttpURLConnection)url.openConnection();  

connection.connect(); ////打開指向圖片的連接

InputStream stream = connection.getInputStream();

BitMap bitmap = BitMapFactory.decodeStream(stream);    //得到圖片對象

stream.close()  //關閉流

 

得到圖片對象後可以顯示在ImageView控件中

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章