手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >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中如何做到Service被关闭后又自动启动的实现方法

Android笔记之:App模块化及工程扩展的应用

Android中使用sax解析xml文件的方法

Android利用方向传感器获得手机的相对角度实例说明

Android中使用Gson解析JSON数据的两种方法

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

精品推荐
分类导航