0

How do I get a bitmap image from InputStream(base64 String) in Android?

Below is my code:

protected Bitmap doInBackground(Void... params) {
    Bitmap image;
    URL url1 = null;
    try {
        url1 = new URL("http://sunnyfacemash.atwebpages.com/get.php"); // url 
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try {
         image = BitmapFactory.decodeStream(url1.openConnection().getInputStream());
         return image;
    } catch (IOException e) {
        image = null;
        e.printStackTrace();
    }
    return image;
}
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47

1 Answers1

-1

Download stream to string, then use Base64.decode on it and feed this to BitmapFactory.

Use ByteArrayInputStream for factory

Petrov Dmitrii
  • 228
  • 1
  • 10