Saturday, 6 April 2013

How to load a remote image from the web?


Load a remote image from the web and return it as Bitmap. 


public Bitmap getRemoteImage(final URL aURL) {
    try {
        final URLConnection conn = aURL.openConnection();
        conn.connect();
        final BufferedInputStream bis = new BufferedInputStream(
               conn.getInputStream());
        final Bitmap bm = BitmapFactory.decodeStream(bis);
        bis.close();
        return bm;
    } catch (IOException e) {
        Log.d("DEBUGTAG", "Oh noooz an error...");
    }
    return null;
}

No comments:

Post a Comment

Disqus for Android