Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display image from URL on Android

I want to display image on screen. Image should come from URL, and not drawable.

Code is here:

<ImageView android:id="@+id/ImageView01" android:src = "http://l.yimg.com/a/i/us/we/52/21.gif"     android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> 

but it gives error at compile time.

How do I display image from URL in Android?

like image 326
Jignesh Ansodariya Avatar asked Jun 20 '11 05:06

Jignesh Ansodariya


People also ask

How do I open an image URL?

On your computer, go to images.google.com. Search for the image. In Images results, click the image. At the top of your browser, click the address bar to select the entire URL.

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

UIL is a powerful and flexible library for loading, caching and displaying images on Android.


1 Answers

You can directly show image from web without downloading it. Please check the below function . It will show the images from the web into your image view.

public static Drawable LoadImageFromWebOperations(String url) {     try {         InputStream is = (InputStream) new URL(url).getContent();         Drawable d = Drawable.createFromStream(is, "src name");         return d;     } catch (Exception e) {         return null;     } } 

then set image to imageview using code in your activity.

like image 148
Chirag Avatar answered Oct 19 '22 14:10

Chirag