gpt4 book ai didi

java - 无法扫描显示图像字符集qr zxing android

转载 作者:行者123 更新时间:2023-12-01 11:31:22 26 4
gpt4 key购买 nike

抱歉我的英语不好。我无法扫描二维图像,我有这个“??????”。我使用 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();
}

最佳答案

我修复了这条线

data = new String(b, "ISO-8859-1");
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2);
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");

及其工作!

关于java - 无法扫描显示图像字符集qr zxing android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30357377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com