我正在尝试使用 ZXing 读取 2D 条形码,它大部分工作正常,只是它不能真正识别一些 UTF-8 字符,如 č 和 ć。我正在使用此代码来设置编码:
MultiFormatReader reader = new MultiFormatReader();
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
reader.setHints(hints);
result = reader.decode(bitmap);
我做错了什么吗?
编辑:我还尝试调用需要提示的解码重载,但结果是相同的。
最佳答案
看起来我创建位图的方式是错误的。这有效:
MultiFormatReader reader = new MultiFormatReader();
FileInputStream fis = new FileInputStream(filePath);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(
ImageIO.read(fis))));
Result result = reader.decode(bitmap);
String originalText = result.getText();
byte[] bytes = originalText.getBytes("ISO-8859-1");
String outputText = new String(bytes, "UTF-8");
关于java - ZXing二维条码解码 : UTF-8 characters not decoded properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30300806/