手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android从服务器获取图片的实例方法
Android从服务器获取图片的实例方法
摘要:[java]复制代码代码如下:publicstaticBitmapgetBitmapFromServer(StringimagePath){...

[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);

【Android从服务器获取图片的实例方法】相关文章:

更新android SDK 失败的解决方法

android图像绘制(六)获取本地图片或拍照图片等图片资源

Android编程实现检测当前电源状态的方法

Android从服务器端获取数据的几种方法

解析android中隐藏与显示软键盘及不自动弹出键盘的实现方法

android,不显示标题的方法小例子

android 从资源中获取数组

android内存优化之图片优化

Android上使用jspf插件框架的方法

Android 开机启动慢的原因分析

精品推荐
分类导航