【问题标题】:ZXing.Net PDF417 Barcode from HEX来自 HEX 的 ZXing.Net PDF417 条码
【发布时间】:2017-01-02 23:33:55
【问题描述】:

是否可以从 HEX 构建 PDF417 条形码?我尝试使用 ZXing,但在我的情况下它不适用于编码字符串。

HEX: fe-30-09-33-31-37-30-31-30-32-30-31-f9-20-01-34-fe-30-01-20-fc-20-06

其他发电机可以做到这一点(https://stackoverflow.com/a/39471232/3236231),但现在这个解决方案要花费几千美元。 ZXing 满足我的所有需求,但我找不到合适的方式来使用我的数据。

【问题讨论】:

    标签: c# barcode zxing


    【解决方案1】:

    以下代码 sn-p 应该可以按预期工作:

      [Test]
      public void Hex2Pdf417()
      {
         var hexStr = "fe3009333137303130323031f9200134fe300120fc2006";
         var byteArray = Enumerable.Range(0, hexStr.Length / 2).Select(x => Convert.ToByte(hexStr.Substring(x * 2, 2), 16)).ToArray();
         var byteArrayAsString = new String(byteArray.Select(b => (char)b).ToArray());
    
         // encode the string as PDF417
         var writer = new BarcodeWriter
         {
            Format = BarcodeFormat.PDF_417,
            Options = new PDF417EncodingOptions
            {
               Height = 200,
               Width = 200,
               Margin = 10
            }
         };
         var bitmap = writer.Write(byteArrayAsString);
    
         // try to decode the PDF417
         var reader = new BarcodeReader
         {
            Options = new DecodingOptions
            {
               PossibleFormats = new List<BarcodeFormat>
               {
                  BarcodeFormat.PDF_417
               },
               PureBarcode = true
            }
         };
         var result = reader.Decode(bitmap);
    
         // make sure, the result is the same as the original hex
         var resultBackToBytes = result.Text.Select(c => (byte)c).ToArray();
         var resultAsHexString = String.Join("", resultBackToBytes.Select(b => b.ToString("x2")));
    
         Assert.That(resultAsHexString, Is.EqualTo(hexStr));
      }
    

    【讨论】:

    • CP850 中的“81”等 HEX 引发错误:检测到不可编码字符:(Unicode:132)此外,当我在 online-barcode-reader.inliteresearch.com 解码条形码时,它显示保存的 HEX 数据不是原始的 HEX。 “FE”保存为“5F”。
    • 由于ZXing.Net当前版本0.14的一些小错误,代码在所有情况下都不能正常工作。
    • 非常感谢!它与源代码中的当前版本完美配合!自编自github.com/micjahn/ZXing.Net!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2019-06-01
    • 1970-01-01
    相关资源
    最近更新 更多