fetch Bitmap from URL - Android Graphics

Android examples for Graphics:Bitmap URL

Description

fetch Bitmap from URL

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static Bitmap fetchBitmap(String src) {
        Bitmap bitmap = null;/*from w  w  w .  j av a  2s . c  o m*/
        URL url = null;
        try {
            url = new URL(src);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
        try {
            final InputStream is = url.openStream();
            bitmap = BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }
}

Related Tutorials