【发布时间】:2021-05-16 22:33:36
【问题描述】:
我想使用 ZXing 生成二维码并在屏幕上显示,但是我要求二维码显示在特定背景 [图像] 上。 ZXing可以吗?
谢谢
编辑: 能够将状态栏标题从纯文本 [我正在使用 TYPE_TEXT] 更改为其他内容也很棒。
【问题讨论】:
我想使用 ZXing 生成二维码并在屏幕上显示,但是我要求二维码显示在特定背景 [图像] 上。 ZXing可以吗?
谢谢
编辑: 能够将状态栏标题从纯文本 [我正在使用 TYPE_TEXT] 更改为其他内容也很棒。
【问题讨论】:
只需create the barcode image using the library 并将其显示在您自己的活动中。你可以随心所欲地设计它。
【讨论】:
startActivityForResult 时没有返回任何结果。我正在尝试以“正确”的方式使用它 - 有意图。如果我要将 zxing 作为 lib 包含在我的应用中,我只需修改现有布局即可。
这是如何使用 ZXING 库创建透明二维码的示例:
QRCodeWriter qrCodeWriter = new QRCodeWriter();
// create output image
BufferedImage image = new BufferedImage(382, 382, BufferedImage.TYPE_INT_ARGB);
// create bit matrix
BitMatrix bitMatrix = new MultiFormatWriter().encode(
qrCodeString,
BarcodeFormat.QR_CODE, 382, 382);
// set pixels of output image based of bit matrix (black or translucent)
for (int i = 0; i < 382; i++) {
for (int j = 0; j < 382; j++) {
image.setRGB(i,j, bitMatrix.get(i,j) ? Color.BLACK.getRGB() : Color.TRANSLUCENT);
}
}
// write output image as png
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "PNG", outputStream);
【讨论】:
没有办法。通常,条形码周围需要一个安静的白色区域,因此您通常不想这样做。如果你真的需要,你可以编写自己的布局并嵌入与显示相同的代码。
【讨论】: