java - Android:如何将位图图像传递到 ArrayList<Bitmap> 并检索它

标签 java android arraylist bitmap

“Base64Parts”是一个已分割为相等部分的字符串,我试图为每个字符串生成一个 QR 代码并将其放入数组列表中,以便我可以检索它并生成 GIF。我是否以正确的方式将位图图像添加到数组列表中?因为我只能检索“bmp_images.get(0)”。不是其他(例如-bmp_images.get(1))。我的代码如下。

//Declaring QR code generator
QRCodeWriter writer = new QRCodeWriter();

//Declaring Array
ArrayList<Bitmap> bmp_images = new ArrayList<Bitmap>();
for (int i = 0; i < numberOfPartsSplit; i++){

    try {
        Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        BitMatrix bitMatrix = writer.encode(Base64Parts.get(i), BarcodeFormat.QR_CODE, 512, 512, hintMap);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }

        bmp_images.add(i,bmp); //the code added for arraylist of images

        ((ImageView) findViewById(R.id.image_holder)).setImageBitmap(bmp_images.get(0)); //use different values

    } catch (WriterException e) {
        e.printStackTrace();
    }

最佳答案

((ImageView) findViewById(R.id.image_holder)).setImageBitmap(bmp_images.get(0));

将此行粘贴到 for 循环之外。所有迭代完成后,设置所需的索引以获得该特定值。

关于java - Android:如何将位图图像传递到 ArrayList<Bitmap> 并检索它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36035750/

相关文章:

android - 使用 OSMbonuspack_v5.1 创建上下文菜单

java - FileWriter 循环遍历 Arraylist 但不写入文本文件

java - 在函数之外,类变量数组在java中返回null

java - 如何在 Java/Groovy 中将 InputStream 转换为 BufferedImage?

android - 在 Android 中集成 Dibs 支付网关

android - 使用 usbManager android 无法看到鼠标和键盘设备

java - 更新值为 List 的 HashMap 条目

java - 将 TextView 与数组列表链接并在事件发生时更改文本

java - 制作独立的 Java EXE 文件

javascript - Java Nashorn - ClassNotFoundException - Java.type()