How use HTTP post and get to retrieve images?
I would like to use HTTP post and get methods to retrieve images for a gallery vie开发者_JAVA百科w. How would i go about doing this?
Do a search here for how to use HttpGet - there are lots of examples. But once you have a valid response you will need to use BitmapFactory.decodeStream to get a bitmap (something like the example code below) which you can draw into the 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);
}
精彩评论