Friday, August 6, 2010

Show Image from internet in a ImageView in ANDROID

Suppose if you have an Image in web Link and If you need to show that image in an Image View .then You can use the following code.
This code will display an image in an image View based on image Link.

Step 1) Create an Image View 

// Here i am creating image View Dynamically
ImageView img=new ImageView(this);

Step 2) Write a methos which will takes Imagelink as input and returns Bitmap Image as output.
as Follows:

public static Bitmap getImageFromWeb(String imglink)
{

Bitmap bmpImage;

URL imgURL = new URL(imglink);
URLConnection conn = imgURL.openConnection();
conn.connect();

InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);

bmpImage = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
return bmpImage;

}

Step 3) Call the above method to display image in ImageView


img.setBitmap(getImageFromWeb("your image Path Link"));

Note: The above method will return bitmap Image if Link is correct and returns NULL if any error occurred.

By this way we can show an image from internet in a ImageView




4 comments:

  1. It was very good! The perfect solution I was looking for.
    Congratulations!
    In the web, there is dificult to find out some solution perfect and simple like this.

    ReplyDelete
  2. I have read so many content concerning the blogger lovers however this
    piece of writing is truly a fastidious article, keep it up.



    My web site: exercises to improve vertical leap

    ReplyDelete
  3. Pretty! This was an incredibly wonderful article. Thanks for supplying this info.


    Here is my webpage :: vertical jump workouts

    ReplyDelete
  4. Hello there! This post couldn't be written any better! Going through this post reminds me of my previous roommate! He always kept preaching about this. I'll forward this information to him.
    Fairly certain he'll have a very good read. Thank you for sharing!

    My web site Sporting Goods darts

    ReplyDelete

Android Developers Blog

Ram's shared items