Android: How to pass Bitmap Images to ArrayList<Bitmap> and retrieve it

"Base64Parts" is a string that has been split to equal parts, and I am trying to generate a QR code for each string and place it in a arraylist so that i can retrieve it and generate a GIF. Am I adding the bitmap images to the arraylist in the correct way? Because i can only retrieve "bmp_images.get(0)". Not others (eg-bmp_images.get(1)). My code is given below.

//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();
    }

Answers


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

paste this line outside for loop. Once all iteration done, set the needed index to get that particular value.


Need Your Help

Trying to connect to coap resource with python library

python python-asyncio coap

So im trying to connect to a CoaP Resource using this python library https://github.com/chrysn/aiocoap . The library uses python 3.4 and i have 3.4 installed and set as the interpreter to use with ...

Objective C ARC equivalent for self?

iphone objective-c ios automatic-ref-counting xcode4.3

What is the equivalent keyword i can use in the place of self in ARC enabled projects?