4

ZXing.dll -- zxing.net for .net 2.0 -- 文件版本 0.14.0.1

我的应用程序不允许 PDF417 代码的自动调整大小(行/列计算)。因此,我使用选定的设置来确定应该允许多少个字符,然后限制用户输入。

根据我的计算,ZXing 在对 PDF417Writer.encode 的调用中抛出“无法将消息放入列”异常,给定的参数应该是有效的。

示例 #1:

ErrorCorrection=Level3 (16 error codewords)
Compaction=Text (1.9 characters per codeword)
Rows=23, Columns=3 (69 codewords)
Calculated Capacity = 69 - 16 - 1 = 52 * 1.9 = 98.8 (98 characters)
Text = "0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGH"
(98 text characters)

使用这些设置,ZXing 可以编码 94 个字符,但无法编码 95 个或更多字符。

示例 #2:

ErrorCorrection=Level0 (2 error codewords)
Compaction=Numeric (2.9 characters per codeword)
Rows=3, Columns=2 (6 codewords)
Calculated Capacity = 6 - 2 - 1 = 3 * 2.9 = 8.7 (8 characters)
Text = "123456" (6 numeric characters)

在这种情况下,ZXing 最多可以编码 5 个字符,但不能编码 6 个或更多字符。

这是一个重现示例 #2 的小型测试程序 (C#):

IDictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
hints.Add(EncodeHintType.MARGIN, 0);
hints.Add(EncodeHintType.ERROR_CORRECTION, PDF417ErrorCorrectionLevel.L0);
hints.Add(EncodeHintType.PDF417_COMPACT, false);
hints.Add(EncodeHintType.PDF417_COMPACTION, Compaction.NUMERIC);
hints.Add(EncodeHintType.PDF417_DIMENSIONS, new Dimensions(2, 2, 3, 3));
new PDF417Writer().encode("123456", BarcodeFormat.PDF_417, 0, 0, hints);

以下资源解释了示例 #1:

http://www.currentdirections.com/facts/sizing-applications-for-2d-symbols.html

问题:

  1. 我是否以正确的方式使用 ZXing 来生成 PDF417 代码数据?
  2. 我是否正确计算 PDF417 代码的容量?
4

0 回答 0