Showing posts with label android code samples. Show all posts
Showing posts with label android code samples. Show all posts

July 08, 2011

Code Sample for Downlaoding Image via 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;
}