Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an image from the internet in android?

Tags:

android

How can I display image in an ImageView in android from a URL (from the internet)?

like image 487
Adham Avatar asked Nov 19 '10 09:11

Adham


People also ask

Which library do we use to display images from Internet in Android?

Official Google apps are also using Glide. Glide is an Image Loader Library in Android developed by bumptech and is a library that is backed by Google.


1 Answers

You can use the method setImageDrawable

ImageView iv = new ImageView;

URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

[2014-12-16] Edit: Using Picasso, makes your life much simplier

String url = "http://i.imgur.com/bIRGzVO.jpg";
ImageView iv = new ImageView;

Picasso.with(context).load(url).into(iv);
//Picasso.with(context).load(url).centerCrop().fit().into(iv);
like image 120
SteD Avatar answered Sep 28 '22 06:09

SteD