码迷,mamicode.com
首页 > 移动开发 > 详细

安卓 获取网站图片

时间:2015-05-16 17:51:56      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:


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是你的图片路径,

 


最后可以将图片显示在手机上:




imageView.setImageBitmap(bitmap); 

安卓 获取网站图片

标签:

原文地址:http://www.cnblogs.com/yang95/p/4508083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!