I have some images in a database. The images are sent to Android Studio in the base64 format from the database using an API. How can I display these images using a ListView
.
Asked
Active
Viewed 108 times
-1
-
Please post what have you tried. – Ashish Aug 16 '19 at 09:20
-
There is answer how to convert the [Base64 to Bitmap](https://stackoverflow.com/a/4837293/10182897). – Ashish Aug 16 '19 at 09:22
-
Which database/API? – Yash Aug 16 '19 at 09:25
-
*images are sent to android studio* -> How? – Manoj Perumarath Aug 16 '19 at 10:07
2 Answers
0
You can use method to decode Bitmap from Base64 string to Bitmap:
Kotlin version:
fun getBitmapFromBase64(String input) : Bitmap {
val decodedBytes = Base64.decode(input, 0)
return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length)
}
Java version:
public Bitmap getBitmapFromBase64(String input){
byte[] decodedBytes = Base64.decode(input, 0);
return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}
after that you can set this method:
youImageView.setImageBitmap(/*your bitmap*/)
in your adapter.

Peter Staranchuk
- 1,343
- 3
- 14
- 29
0
Replace your base64 value with encodedImage.
val encodedImage = "data:image/jpeg;base64,..."
val decodedString = Base64.decode(encodedImage, Base64.DEFAULT)
val decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
Glide
.with(this)
.load(decodedByte)
.into(<Your ImageView>)

Rishabh Jain
- 145
- 8