ZXing FormatException解码ZXing生成的QRCode(ZXing FormatException decoding ZXing generated QRCode)

编程入门 行业动态 更新时间:2024-10-25 21:17:38
ZXing FormatException解码ZXing生成的QRCode(ZXing FormatException decoding ZXing generated QRCode)

下面的代码使用ZXing编码一个字节数组(长度为35,所有元素为0) ,然后再次对其进行解码,编码- 解码 - 随机 - 字节 - 数组 - 带有zxing 。

package zxing.sandpit; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.ChecksumException; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.RGBLuminanceSource; import com.google.zxing.Result; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeReader; import com.google.zxing.qrcode.QRCodeWriter; import java.awt.image.BufferedImage; import java.io.UnsupportedEncodingException; public class Problem { public static void main(String[] args) throws UnsupportedEncodingException, WriterException, NotFoundException, ChecksumException, FormatException { byte[] bytes = new byte[35]; String dataString = new String(bytes, "ISO-8859-1"); QRCodeWriter writer = new QRCodeWriter(); BitMatrix bitMatrix = writer.encode( dataString, BarcodeFormat.QR_CODE, 256, 256); System.out.println("A"); BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix); System.out.println("B"); final Result result = new QRCodeReader().decode( new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(image.getWidth(), image.getHeight(), image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()))))); System.out.println("C"); byte[] bytes1 = result.getText().getBytes("ISO8859_1"); } }

对于长度小于35的所有数组,完美工作,对于数组大小35,引发FormatException并且不会打印C

A B Exception in thread "main" com.google.zxing.FormatException

我犯了什么错误?

The following code, derived from encoding-and-decoding-random-byte-array-with-zxing, encodes a byte array (of length 35 and all elements 0) using ZXing and then decodes it again.

package zxing.sandpit; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.ChecksumException; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.RGBLuminanceSource; import com.google.zxing.Result; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeReader; import com.google.zxing.qrcode.QRCodeWriter; import java.awt.image.BufferedImage; import java.io.UnsupportedEncodingException; public class Problem { public static void main(String[] args) throws UnsupportedEncodingException, WriterException, NotFoundException, ChecksumException, FormatException { byte[] bytes = new byte[35]; String dataString = new String(bytes, "ISO-8859-1"); QRCodeWriter writer = new QRCodeWriter(); BitMatrix bitMatrix = writer.encode( dataString, BarcodeFormat.QR_CODE, 256, 256); System.out.println("A"); BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix); System.out.println("B"); final Result result = new QRCodeReader().decode( new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(image.getWidth(), image.getHeight(), image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()))))); System.out.println("C"); byte[] bytes1 = result.getText().getBytes("ISO8859_1"); } }

While working perfectly for all arrays of length less than 35, for array size 35, a FormatException is thrown and C is never printed.

A B Exception in thread "main" com.google.zxing.FormatException

What mistake am I making?

最满意答案

ZXing在生成的qr代码中检测到错误的标记(误报)。 特别是在使用合成图像的情况下。 尝试解码提示PURE_BARCODE。

ZXing detects a wrong marker (false positive) within the generated qr code. That happens especially if synthetic images are used. Try the decoding hint PURE_BARCODE.

更多推荐

本文发布于:2023-07-17 04:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FormatException   ZXing   QRCode   generated   decoding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!