使用zxing库生成QR时如何在QR码中编码多条记录?
How to encode multiple records in QR code while generating QR using zxing library?
我在 QR 码生成器和扫描器中工作,我在 android 中使用 zxing 库成功地在 QR 码中编码单个字符串记录,但现在我想编码多个记录,如姓名、地址、电子邮件等
我该怎么做?
这是使用 zxing 在 QR 中编码单个记录的代码:
public Bitmap encodeQR(String value) throws WriterException {
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(value, BarcodeFormat.QR_CODE, 512, 512);
} catch (WriterException e) {
e.printStackTrace();
return null;
}
return new BarcodeEncoder().createBitmap(bitMatrix);
}
您可以使用您需要的任何数据创建一个 JSON 并将其转换为字符串
并且在需要时很容易从 JSON 中提取数据。
例如:
{
"question": "Do you smoke?",
"options": [
"Yes",
"No"
]
}
我在 QR 码生成器和扫描器中工作,我在 android 中使用 zxing 库成功地在 QR 码中编码单个字符串记录,但现在我想编码多个记录,如姓名、地址、电子邮件等 我该怎么做?
这是使用 zxing 在 QR 中编码单个记录的代码:
public Bitmap encodeQR(String value) throws WriterException {
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(value, BarcodeFormat.QR_CODE, 512, 512);
} catch (WriterException e) {
e.printStackTrace();
return null;
}
return new BarcodeEncoder().createBitmap(bitMatrix);
}
您可以使用您需要的任何数据创建一个 JSON 并将其转换为字符串
并且在需要时很容易从 JSON 中提取数据。
例如:
{
"question": "Do you smoke?",
"options": [
"Yes",
"No"
]
}