【发布时间】:2011-07-19 19:44:37
【问题描述】:
我想使用 HTTP post 和 get 方法来检索画廊视图的图像。 我该怎么做呢?
【问题讨论】:
标签: android
我想使用 HTTP post 和 get 方法来检索画廊视图的图像。 我该怎么做呢?
【问题讨论】:
标签: android
在这里搜索如何使用 HttpGet - 有很多示例。但是一旦你有一个有效的响应,你将需要使用 BitmapFactory.decodeStream 来获取一个位图(类似于下面的示例代码),你可以将其绘制到 ImageView 中。
HttpResponse response = HttpClient.execute(request);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
InputStream inputStream = entity.getContent();
Bitmap rawBitmap = null;
BitmapFactory.Options bitmapOpt = new BitmapFactory.Options();
bitmapOpt.inDither = true;
bitmapOpt.inPurgeable = true;
bitmapOpt.inInputShareable = true;
bitmapOpt.inTempStorage = null;
rawBitmap = BitmapFactory.decodeStream(inputStream, null, bitmapOpt);
}
【讨论】: