Alex Rivera | Logout

Is it possible to use BitmapFactory.decodeFile method to decode a image from http location?

Asked 2010-12-22T14:02:16.280
11

I would like to know if it is possible to use BitmapFactory.decodeFile method to decode a image from http location?

For eg.

ImageView imageview = new ImageView(context);
Bitmap bmp = BitmapFactory.decodeFile("http://<my IP>/test/abc.jpg");  
imageview.setImageBitmap(bmp);

But bmp is always returning null.

Is there any other way to achieve this scenario, where i have a set of images in my server PC, and i am loading the images to my gallery application via an xml?

Thanks,
Sen

Edit
Report

1 Answer

2

If I'm not mistaken, @Sen code snippet should return null in case of .BMP file and logcat should log:

skia decoder->decode returned false

If something like this is happening, try using this code (works also in case of bitmap input):

HttpGet httpRequest = null;

try {
    httpRequest = new HttpGet(url.toURI());
} catch (URISyntaxException e) {
    e.printStackTrace();
}

HttpClient httpclient = new DefaultHttpClient();

HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

HttpEntity entity = response.getEntity();

BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);

InputStream instream = bufHttpEntity.getContent();

bmp = BitmapFactory.decodeStream(instream);

Source

answered 2011-07-08T08:35:06.727

Your Answer