亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android從服務(wù)器獲取圖片的實(shí)例方法

 更新時間:2013年06月04日 10:48:39   作者:  
Android從服務(wù)器獲取圖片的實(shí)例方法,需要的朋友可以參考一下

[java]

復(fù)制代碼 代碼如下:

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]

復(fù)制代碼 代碼如下:

imageView.setImageBitmap(bitmap);

相關(guān)文章

最新評論