Chandra Sekhar Chandra Sekhar - 1 year ago 161
Android Question

How to get bitmap from a url in android?

I have a uri like which has an image


How to use this uri to get the image but it returns null, please tell me where i am wrong.

Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());
Bitmap bitmap = BitmapFactory.decodeFile(uri.toString());

Answer Source

This is a simple one line way to do it:

    try {
        URL url = new URL("http://....");
        Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    } catch(IOException e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download