Android:如何将位图图像传递给ArrayList <bitmap>并检索它

时间:2016-03-16 12:30:02

标签: java android arraylist bitmap

“Base64Parts”是一个已被拆分为相等部分的字符串,我正在尝试为每个字符串生成QR代码并将其放在arraylist中,以便我可以检索它并生成GIF。我是否以正确的方式将位图图像添加到arraylist?因为我只能检索“bmp_images.get(0)”。不是其他人(eg-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();
    }

1 个答案:

答案 0 :(得分:0)

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

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

相关问题