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 出現(xiàn):java.lang.NoClassDefFoundError...錯誤解決辦法
這篇文章主要介紹了Android 出現(xiàn):Android出現(xiàn):java.lang.NoClassDefFoundError: android/os/PersistableBundle錯誤解決辦法的相關(guān)資料,需要的朋友可以參考下2017-03-03Android(2.2/2.3系統(tǒng))Gallery解決默認(rèn)和橫豎屏切換選中狀態(tài)問題
本文主要介紹Android Gallery,在Android開發(fā)過程中肯定會遇到版本不同,在開發(fā)過程中需要調(diào)整的,這里針對Android(2.2/2.3系統(tǒng)版本) Gallery解決默認(rèn)和橫豎屏切換選中狀態(tài)問題2016-07-07Android學(xué)習(xí)筆記--Activity中使用Intent傳值示例代碼
Intent負(fù)責(zé)對應(yīng)用中一次操作的動作、動作涉及數(shù)據(jù)、附加數(shù)據(jù)進(jìn)行描述,Android則根據(jù)此Intent的描述,負(fù)責(zé)找到對應(yīng)的組件,將Intent傳遞給調(diào)用的組件,并完成組件的調(diào)用2013-06-06Sql Server2008遠(yuǎn)程過程調(diào)用失敗的解決方法
這篇文章主要為大家詳細(xì)介紹了Sql Server2008遠(yuǎn)程過程調(diào)用失敗的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07Android自定義View圖片按Path運(yùn)動和旋轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Android自定義View圖片按Path運(yùn)動和旋轉(zhuǎn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01android 控件同時監(jiān)聽單擊和雙擊實(shí)例
這篇文章主要介紹了android 控件同時監(jiān)聽單擊和雙擊實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08Android?DialogFragment使用之底部彈窗封裝示例
這篇文章主要為大家介紹了Android?DialogFragment使用之底部彈窗封裝示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09