Am trying to get a image from a http response, but am failing to convert the stream to bitmap. Please let me know, what am i missing here.
FYI - the image content is received as raw binary & its a jpeg image.
Procedure followed:
- Make HttpRequest.
- In response check for 200 -> get the httpentity content.
- convert the stream to bitmap using BitMap factory.
- Set the bitmap to imageview
Doing this in postExecute of the AsyncTask
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(endpoint);
// Adding Headers ..
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
// Get hold of the response entity
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
return instream;
// instream.close();
}
}
}
Doing this in postExecute of the AsyncTask
if (null != instream) {
Bitmap bm = BitmapFactory.decodeStream(instream);
if(null == bm){
Toast toast = Toast.makeText(getApplicationContext(),
"Bitmap is NULL", Toast.LENGTH_SHORT);
toast.show();
}
ImageView view = (ImageView) findViewById(R.id.picture_frame);
view.setImageBitmap(bm);
}
Thanks in Advance.