【问题标题】:Problems in generating a proper qr-code using zxing使用 zxing 生成正确的二维码的问题
【发布时间】:2013-03-18 20:27:16
【问题描述】:

我在使用 zxing api 生成正确的二维码时遇到问题。 我能够生成一个二维码,但是当我阅读二维码时,像“äü”这样的字符并没有正确显示。

代码:

BitMatrix matrix = writer.encode(text, BarcodeFormat.QR_CODE, 200,200);
//text is String text = "geändert";

bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);

如果我以“ü”开头,然后是“äö”,则显示正确 谁知道为什么?

【问题讨论】:

  • 你确定是二维码错了,而不是你用什么解码?
  • 是的,我已经在 iphone 上尝试了 3 个二维码“阅读器”
  • 我写了一个答案,使用zxing生成Stack Overflow: qr-code-integration-in-jasperreport中的二维码。如果符合您的要求,您可以使用它。

标签: java qr-code zxing


【解决方案1】:

您可以从下面的代码中读取zxing api的二维码。

binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream("QR_Code.JPG")))));
        result = new MultiFormatReader().decode(binaryBitmap);
        System.out.println("QR Code : "+result.getText());

【讨论】:

    【解决方案2】:

    如果您查看来自 zxing http://code.google.com/p/zxing/wiki/DeveloperNotes 的开发人员文档,您会发现他们明确讨论了非拉丁字符的问题。

    由于 QR 码标准没有定义在 QR 码中指定字符编码的确切方法,因此建议仅使用出现在所有三种标准编码(ISO-8859-1、ISO-8859-15、 UTF-8)

    【讨论】:

      【解决方案3】:

      在您通过编码器的提示的Hashtable 中,将EncoderHintType.CHARACTER_SET 设置为"UTF-8"。 Barry 的回答是正确的,但强制它尝试 UTF-8 可能对您更有效。

      【讨论】:

      • 感谢 sean 对哈希表的提示!!我还必须在字符串中添加一个 UTF-8 BOM,但现在它可以工作了!非常感谢
      【解决方案4】:

      您可以从下面的代码中读取zxing api的二维码。

      binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream("QR_Code.JPG"))))); 
      
      result = new MultiFormatReader().decode(binaryBitmap); 
      
      System.out.println("QR Code : "+result.getText());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-14
        • 2014-04-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多