【发布时间】:2016-03-16 12:30:01
【问题描述】:
"Base64Parts" 是一个被分割成相等部分的字符串,我正在尝试为每个字符串生成一个 QR 码并将其放在一个数组列表中,以便我可以检索它并生成一个 GIF。我是否以正确的方式将位图图像添加到数组列表中?因为我只能检索“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();
}
【问题讨论】:
-
我已经用 ((ImageView) findViewById(R.id.image_holder)).setImageBitmap(bmp_images.get(0));在 for 循环之外。然后我也没有得到索引“0”的任何输出
-
如果你有base 64那么直接将它们保存为字符串为什么要转换为位图?
-
@VivekMishra 我的主要目的是生成多个二维码位图图像。所以,arraylists 似乎是唯一的存储方式
-
但是 base64 本身就是字符串,所以为什么你首先将它们转换为位图然后保存它。需要时将保存的字符串转换为位图
-
我正在尝试保存它,以便我可以再次使用这些图像来创建 GIF 或视频。
标签: java android arraylist bitmap