How to read image from specific url in android

how to read image from specific url in android?

+4
source share
3 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 ); 
+11
source

Below is the code to help you read the image. But remember that if you do this in UI Thread, then it depends on the user interface. You should always open a new stream and load the image into this stream. Therefore, your application always remains 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 ); 
+5
source

This has already been discussed in this link.

Refer to this, it will be fruitful.

Have a happy coding ... !!!

0
source

Source: https://habr.com/ru/post/1332183/


All Articles