生成阿拉伯语QR码

时间:2016-09-29 04:44:40

标签: java android qr-code zxing

在我的应用程序中,我使用阿拉伯语生成QR名称,然后扫描并使用zxing库生成但似乎zxing库不支持阿拉伯语,因为当我扫描生成的名称时它给了我????。解决方案是什么?

这是我要生成的代码:

 BitMatrix bitMatrix = multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500);
 BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
 bitmap = barcodeEncoder.createBitmap(bitMatrix);
 imageView = (ImageView) findViewById(R.id.imageView);
 imageView.setImageBitmap(bitmap);

2 个答案:

答案 0 :(得分:1)

我找到了解决方案:

MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);

hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hintMap.put(EncodeHintType.MARGIN, 1); /* default = 4 */
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

BitMatrix bitMatrix = multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hintMap);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
bitmap = barcodeEncoder.createBitmap(bitMatrix);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);

答案 1 :(得分:0)

别忘了设置文字编码。 Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

所以,基于你的代码应该是 multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hints);

相关问题