我试图在我的应用程序中生成qr代码。
我尝试了几个关于堆栈溢出的答案。
How can I generate multiple values QR code in android studio Generate designer 2d QR code in android
我可以使用这个库- https://github.com/kenglxn/QRGen生成QR代码。
但是qr码扫描器不能读取由这个库生成的qr码,尽管它能够读取其他qr码。
有没有可靠的方法在android应用上生成qr代码?
发布于 2020-01-26 06:47:33
不用使用QRGen,您可以直接在android应用程序中使用Zxing库,并使用下面所示的代码生成QRcode
QRCodeWriter writer = new QRCodeWriter();
try {
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);
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);
}
}
((ImageView) findViewById(R.id.img_result_qr)).setImageBitmap(bmp);
} catch (WriterException e) {
e.printStackTrace();
}
若要向项目中添加Z行库,可以将其粘贴到您的gradle依赖项文件中
repositories {
jcenter()
}
dependencies {
implementation 'com.google.zxing:core:3.3.0'
}
https://stackoverflow.com/questions/59915955
复制相似问题