抱歉我的英文。我不能扫描qr图像,我有这个“???????”。我用zxing库。我尝试但没有成功。我的代码。字符串等于俄罗斯字符集。我不知道为什么扫描实例符号来??????。
final QRCodeWriter writer = new QRCodeWriter();
ImageView tnsd_iv_qr = (ImageView)findViewById(R.id.qrImage);
Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
byte[] b = null;
try {
// Convert a string to UTF-8 bytes in a ByteBuffer
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(summ.getText().toString() + "/"
+ getNumber.substring(1) + "/"
+ getName + "/"
+ getIdDepartament + "/"
+ getIdUser + "/"
+ getSpinnerItem));
b = bbuf.array();
} catch (CharacterCodingException e) {
//
}
String data;
try {
data = new String(b, "UTF-8");
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
ByteMatrix bitMatrix = writer.encode( data
,BarcodeFormat.QR_CODE, 512, 512, hints);
int width = 512;
int height = 512;
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (bitMatrix.get(x, y)==0)
bmp.setPixel(x, y, Color.BLACK);
else
bmp.setPixel(x, y, Color.WHITE);
}
}
tnsd_iv_qr.setImageBitmap(bmp);
} catch (WriterException | UnsupportedEncodingException e) {
e.printStackTrace();
}
答案 0 :(得分:1)
我修好了这一行
data = new String(b, "ISO-8859-1");
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2);
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
及其工作!