生成阿拉伯语二维码
Generate Arabic QR Code
在我的应用程序中,我生成了一个阿拉伯语的 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);
别忘了设置文本编码。
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
因此,根据您的代码,它应该是
multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hints);
我找到了解决方案:
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);
在我的应用程序中,我生成了一个阿拉伯语的 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);
别忘了设置文本编码。
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
因此,根据您的代码,它应该是
multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hints);
我找到了解决方案:
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);