简体   繁体   English

从数据库中检索图像列表并使用 ListView 显示它们?

[英]Retrieve a list of images from the Database and display them using a ListView?

I have some images in a database.我在数据库中有一些图像。 The images are sent to Android Studio in the base64 format from the database using an API.这些图像使用 API 从数据库以 base64 格式发送到 Android Studio。 How can I display these images using a ListView .如何使用ListView显示这些图像。

You can use method to decode Bitmap from Base64 string to Bitmap:您可以使用方法将位图从 Base64 字符串解码为位图:

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.在您的适配器中。

Replace your base64 value with encodedImage.用encodedImage 替换你的base64 值。

  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>)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Android从数据库中的列表视图显示图像列表? - How to display list of images in listview from database using android? Android Java ListView从Firebase数据库检索列表,但显示空的TextViews和图像 - Android Java ListView retrieve the list from Firebase database but display empty TextViews and Images 如何从数据库中获取图像并将其显示在列表视图中? - How to fetch images from database and display them in listview? 借助存储在数据库中的路径从存储中检索图像并显示在listView中 - Retrieve images from storage with the help of path saved in database and display in listView 从数据库中检索数据并将其显示在屏幕上 - Retrieve data from database and display them to screen 无法从数据库检索数据并在列表视图中显示 - Cannot retrieve data from database and display in listview 如何在android SQLite数据库中存储和检索图像并将它们显示在gridview上 - how to store and retrieve images in android SQLite database and display them on a gridview 从mysql(BLOB)中检索图像并将其显示到ListView中 - Retrieve Image from mysql (BLOB) and display them into ListView 如何从Firebase数据库检索子值并将其显示在布局列表中? - How to retrieve child values from firebase database and display them in a list of layouts? 如何从URL中检索多个图像并将其显示在Android的图库中? - How to retrieve mutiple images from url and display them in a gallery in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM