[英]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. “Base64Parts”是一个已被拆分为相等部分的字符串,我正在尝试为每个字符串生成一个QR代码并将其放在一个arraylist中,以便我可以检索它并生成一个GIF。 Am I adding the bitmap images to the arraylist in the correct way? 我是否以正确的方式将位图图像添加到arraylist? Because i can only retrieve " bmp_images.get(0)
". 因为我只能检索“ bmp_images.get(0)
”。 Not others (eg-bmp_images.get(1))
. 不是其他人(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();
}
((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. 完成所有迭代后,设置所需的索引以获取该特定值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.