Android如何从服务器获取图片
2013-06-19 18:58
471 查看
[<a
href="http://www.tsingyuan.cn/course_subject/64d0e38639e1465eb1e5e7f973945de4">java</a>]
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();
<img
src="http://bbs.tsingyuan.cn/static/image/smiley/default/huffy.gif" border="0" smilieid="5" alt="">
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();<img
src="http://bbs.tsingyuan.cn/static/image/smiley/default/huffy.gif"
border="0" smilieid="5" alt="">
InputStream is = entity.getContent();
pic = BitmapFactory.decodeStream(is); //
关键是这句代码
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pic;
}
其中
imagePath
是你的图片路径,
最后可以将图片显示在手机上:
[<a
href="http://www.tsingyuan.cn/course_subject/64d0e38639e1465eb1e5e7f97394
5de4">java</a>]
imageView.setImageBitmap(bitmap);
[<a
href="http://www.tsingyuan.cn/course_subject/64d0e38639e1465eb1e5e7f973945de4">java</a>]
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();
<img
src="http://bbs.tsingyuan.cn/static/image/smiley/default/huffy.gif" border="0" smilieid="5" alt="">
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();<img
src="http://bbs.tsingyuan.cn/static/image/smiley/default/huffy.gif"
border="0" smilieid="5" alt="">
InputStream is = entity.getContent();
pic = BitmapFactory.decodeStream(is); //
关键是这句代码
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pic;
}
其中
imagePath
是你的图片路径,
最后可以将图片显示在手机上:
[<a
href="http://www.tsingyuan.cn/course_subject/64d0e38639e1465eb1e5e7f97394
5de4">java</a>]
imageView.setImageBitmap(bitmap);
相关文章推荐
- Android如何从服务器获取图片
- Android如何从服务器获取图片
- Java乔晓松-android使用ImageSwitcher布局的电子相册&服务器获取图片
- Android中如何根据图片url路径来获取网络图片
- Android通过IO流获取服务器的图片数据
- android 加载图片本地有缓存,如何实时更新服务器上修改的图片
- Android 如何从相册(gallery)获取一张图片?
- Android 显示获取服务器的超大图片 <19>
- android换肤功能中,如何动态获取控件中背景图片的资源id?
- [转]Android 如何根据网络地址获取网络图片方法
- android 如何获取手机的图片、视频、音乐
- android如何用imageloader获取bitmap图片
- Android 如何获取网络上的图片
- Android从服务器获取图片的实例方法
- 如何从服务器获取图片
- android如何简单便捷的获取图片类型信息
- 在Android系统的"图库"中点击某张图片进行分享,在自己的应用程序中如何获取那张图片的路径?
- android从本地媒体库获取图片上传至服务器保存
- android如何在拍照时候获取高清图片
- android如何获取一张图片(照相跟图库)