ZXing.Net 来自 HEX 的 PDF417 条码
ZXing.Net PDF417 Barcode from HEX
是否可以从 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
其他发电机可以做到这一点 (),但现在这个解决方案要花费几千美元。 ZXing 满足我的所有需求,但我找不到合适的方式来使用我的数据。
以下代码片段应按预期工作:
[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));
}
是否可以从 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
其他发电机可以做到这一点 (
以下代码片段应按预期工作:
[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));
}