Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read image from particular url in android

Tags:

android

http

url

how to read image from particular url in android?

like image 449
user538626 Avatar asked Dec 15 '10 05:12

user538626


People also ask

How do I use image URL in react?

How do I use image URL in React? To display an image from a local path in React: Download the image and move it into your src directory. Import the image into your file, e.g. import MyImage from './thumbnail. webp' .

How will you load an image into an ImageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.


2 Answers

Use this

URL url = new URL(imageUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);  

imageView.setImageBitmap(img );
like image 146
Labeeb Panampullan Avatar answered Nov 02 '22 06:11

Labeeb Panampullan


Below code should help you for reading image. But remember that if you do this in UI Thread then it hangs UI. You should always open a new thread and load image in that thread. So your app always remain responsive.

InputStream is = null;
BufferedInputStream bis = null;
Bitmap bmp = null;
try {
   URLConnection conn = url.openConnection();
   conn.connect();
   is = conn.getInputStream();
   bis = new BufferedInputStream( is );
   bmp = BitmapFactory.decodeStream( bis );
} catch (MalformedURLException e) {

} catch (IOException e) {

} finally {
   try {
      is.close();
      bis.close();
   } catch (IOException e) {

   }
}
imageView.setImageBitmap( bmp );
like image 24
Umakant Patil Avatar answered Nov 02 '22 06:11

Umakant Patil