Android從服務(wù)器獲取圖片的實(shí)例方法
[java]
public static Bitmap getBitmapFromServer(String imagePath) {
HttpGet get = new HttpGet(imagePath);
HttpClient client = new DefaultHttpClient();
Bitmap pic = null;
try {
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
pic = BitmapFactory.decodeStream(is); // 關(guān)鍵是這句代碼
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pic;
}
public static Bitmap getBitmapFromServer(String imagePath) {
HttpGet get = new HttpGet(imagePath);
HttpClient client = new DefaultHttpClient();
Bitmap pic = null;
try {
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
pic = BitmapFactory.decodeStream(is); // 關(guān)鍵是這句代碼
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pic;
}
其中imagePath是你的圖片路徑,
最后可以將圖片顯示在手機(jī)上:
[java]
imageView.setImageBitmap(bitmap);
相關(guān)文章
android studio 3.6.0 綁定視圖新特性的方法
這篇文章主要介紹了android studio 3.6.0 綁定視圖新特性的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android自定義控件實(shí)現(xiàn)顏色選擇器
這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)顏色選擇器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
Android學(xué)習(xí)之Span的使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android中各種Span類的使用方法,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Android有一定的幫助,需要的可以參考一下2022-06-06
Android自定義View實(shí)現(xiàn)BMI指數(shù)條
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)BMI指數(shù)條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
Android Service判斷設(shè)備聯(lián)網(wǎng)狀態(tài)詳解
本文主要介紹Android Service判斷聯(lián)網(wǎng)狀態(tài),這里提供了相關(guān)資料并附有示例代碼,有興趣的小伙伴可以參考下,幫助開發(fā)相關(guān)應(yīng)用功能2016-08-08

