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
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
It was very good! The perfect solution I was looking for.
ReplyDeleteCongratulations!
In the web, there is dificult to find out some solution perfect and simple like this.
I have read so many content concerning the blogger lovers however this
ReplyDeletepiece of writing is truly a fastidious article, keep it up.
My web site: exercises to improve vertical leap
Pretty! This was an incredibly wonderful article. Thanks for supplying this info.
ReplyDeleteHere is my webpage :: vertical jump workouts
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.
ReplyDeleteFairly certain he'll have a very good read. Thank you for sharing!
My web site Sporting Goods darts