There is a picture URL, how to download this picture from the URL in Bitmap

  • do you need exactly in Bitmap? Or in ImageView? If the latter, then it is easier to use a bunch of ready-made libraries, for example Picasso square.imtqy.com/picasso - Vladyslav Matviienko
  • @metalurgus I need it in bitmap, then to save to file - Andrew
  • And why not download it as a regular file? - Vladyslav Matviienko

1 answer 1

public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { // Log exception return null; } } 

A source

  • @Fasd If the answer suits you as a solution - tick it off. This way you will save time for other people to view and search for questions that really need someone else’s experience, and not google for others. - Silento
  • This method does not work in android studio, swears on 'connection.connect ();', and it works in eclipse -_- - Andrei
  • @Fasd, in order for the studio to work, you need to connect it with HttpURLConnection - it is cut out by default in new versions of android. - YurySPb
  • @ YuriySPb Thank you - Andrew