Thursday, April 7, 2011

DOWNLOADING IMAGE FROM INTERNET IN ANDROID

public Bitmap downloadImageFromWeb(String url)
{
        Bitmap bitmap = null;
        InputStream in;
        try       
        {
            //Creation of url
            URL url_img = new URL(url);
          
            //Establishing Connection
            in = url_img.openStream();
          
            //Converting input stream to bitmap
            bitmap = BitmapFactory.decodeStream(in);
          
            //Closing the input stream
            in.close();
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return bitmap;
}

No comments:

Post a Comment