gpt4 book ai didi

java - 如何显示 ArrayList 中的图像 (SQLlte)

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:46 25 4
gpt4 key购买 nike

我遇到这个问题,无法在 Android Studio 应用程序的列表中显示数据库中的图像(位图)。

我可以制作一张图片并将其保存(base64)在我的数据库中并检索它。但我不知道如何在显示器上显示所有图像。

我尝试使用列表适配器来完成此操作,但这不起作用:/

 ArrayList<Bitmap> listData = new ArrayList<>();

while(data.moveToNext()){
//get the value from the database in column 1
//then add it to the ArrayList

byte [] encodeByte =Base64.decode(data.getString(1),Base64.DEFAULT);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap =BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
listData.add(bitmap);
}

最佳答案

这是根据listData的大小显示多个 View 的快捷方式。

首先在 your_current_activity.xml 中添加 LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">

</LinearLayout>

在java类中

   LinearLayout linearLayout = findViewById(R.id.linearLayout);
ArrayList<Bitmap> listData = new ArrayList<>();

for (Bitmap a : listData) {
ImageView image = new ImageView(this);
image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80, 60));
image.setMaxHeight(20);
image.setMaxWidth(20);
image.setImageBitmap(a);
linearLayout.addView(image);
}

下面是我的输出(假设 listData 中有 5 个图像)

enter image description here

关于java - 如何显示 ArrayList<Bitmap> 中的图像 (SQLlte),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55666389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com