ZXing二维条码解码:UTF-8字符未正确解码

时间:2015-05-18 10:29:06

标签: java utf-8 barcode zxing

我正在尝试使用ZXing来读取二维条形码,它大部分工作正常,但它不能真正识别某些UTF-8字符,如č和ć。我正在使用此代码来设置编码:

MultiFormatReader reader = new MultiFormatReader();
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");  
reader.setHints(hints);
result = reader.decode(bitmap);

我做错了吗?

编辑:我也尝试调用带有提示的解码重载,但结果是一样的。

1 个答案:

答案 0 :(得分:1)

看起来我正在以错误的方式创建我的位图。这很有效:

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