国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android從服務器獲取圖片的實例方法

2020-04-11 12:15:43
字體:
來源:轉載
供稿:網友

[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);   // 關鍵是這句代碼 

    } 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);   // 關鍵是這句代碼

  } catch (ClientProtocolException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return pic;
 }


其中imagePath是你的圖片路徑,


最后可以將圖片顯示在手機上:


[java]

復制代碼 代碼如下:

imageView.setImageBitmap(bitmap);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 射洪县| 开化县| 白沙| 绥芬河市| 常德市| 东乌珠穆沁旗| 通渭县| 安多县| 介休市| 武宁县| 阜宁县| 格尔木市| 泉州市| 松溪县| 静乐县| 盘山县| 衡阳市| 平邑县| 阳曲县| 盐边县| 调兵山市| 巧家县| 云林县| 永修县| 旌德县| 潍坊市| 烟台市| 阜南县| 淮南市| 莎车县| 宝坻区| 凤翔县| 梁山县| 射阳县| 岳阳市| 罗定市| 仲巴县| 沧州市| SHOW| 调兵山市| 牡丹江市|