2016-09-29 78 views
1

在我的應用程序中,我生成一個阿拉伯語QR碼,然後掃描,我使用zxing庫生成但似乎zxing庫不支持阿拉伯語,因爲當我掃描生成的名稱時,它給了我???? 。解決辦法是什麼?生成阿拉伯文QR碼

這是我的代碼生成:

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

回答

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

不要忘記設置文本編碼。 Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

所以,根據你的代碼應該是 multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hints);

+0

沒有工作,同樣的問題 –

+0

@MarkMamdouh你如何解碼編碼的QR碼?掃描儀/閱讀器可能不支持unicode/arabic嗎? – hakim

+0

我試圖閱讀阿拉伯文,它的工作,但問題是在生成它 –