Mark Mamdouh
Mark Mamdouh

Reputation: 169

Generate Arabic QR Code

In my app I generate a QR name in Arabic and then scan and I use zxing library to generate but it seems that zxing library doesn't support Arabic language because when I scan the generated name it gives me ????. What is the solution?

This is my code to generate:

 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);

Upvotes: 1

Views: 3306

Answers (2)

Mark Mamdouh
Mark Mamdouh

Reputation: 169

I found solution:

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);

Upvotes: 1

hakim
hakim

Reputation: 3909

dont forget to set text encoding. Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

so, based on your code it should be multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hints);

Upvotes: 0

Related Questions