download Image - Android Graphics

Android examples for Graphics:Image Download

Description

download Image

Demo Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap downloadImage(String strUrlImage) {
        Bitmap bitmap = null;/*  ww  w.j a  v  a2  s .  co  m*/
        try {
            URL urlImage = new URL(strUrlImage);
            HttpURLConnection connection = (HttpURLConnection) urlImage
                    .openConnection();
            InputStream inputStream = connection.getInputStream();
            bitmap = BitmapFactory.decodeStream(inputStream);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }
}

Related Tutorials