String path = "www.sjljg.com/image"
//获取HttpClient 对象
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(path);
try {
//请求httpClient
HttpResponse response = httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
System.out.println(is.available());
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
image.setImageBitmap(bitmap);
//或者
// byte[] result = EntityUtils.toByteArray(response.getEntity());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
安卓从网络获取图片
于 2014-08-14 16:00:07 首次发布