【问题标题】:Generate GS1-128 using ZXing.Net使用 ZXing.Net 生成 GS1-128
【发布时间】:2017-08-10 01:32:24
【问题描述】:

我们使用ZXing.Net生成code 128条码,一切正常。

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.CODE_128 };
writer.Write("01950123456789031000012317150801").Save("code128.png", ImageFormat.Png);

最近有人要求我们将格式更改为 GS1-128,经过一番研究,我们发现了使用 FNC1 (ASCII 29) 编写 DataMatrix GS1 的解决方案。 https://stackoverflow.com/a/43575418/823247

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.DATA_MATRIX };
writer.Write($"{(char)29}019501234567890310000123{(char)29}17150801").Save("gs1datamatrix.png", ImageFormat.Png);

但是,如果我们将条形码格式更改为BarcodeFormat.CODE_128,程序将抛出显示Bad character in input:的异常

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.CODE_128 };
writer.Write($"{(char)29}019501234567890310000123{(char)29}17150801").Save("gs1code128.png", ImageFormat.Png);

我们将不胜感激。

【问题讨论】:

    标签: c# barcode zxing.net


    【解决方案1】:

    您必须使用值“(char)0x00F1”而不是“(char)29”作为组分隔符。

    【讨论】:

    • 谢谢!像魅力一样工作!这是否意味着每种条形码格式都有自己的组分隔符?
    • 是和不是。我认为29是最常见的。不知道为什么为 GS1-128 选择了另一个。但这两种条码类型是 zxing for GS1 唯一支持的。
    【解决方案2】:

    有一种更简单的方法可以通过 Zxing.Net 生成 GS1-128 条形码,而无需手动将字符 FNC1 添加到内容中。

    您应该只设置标志 GS1Format = true

    barcodeWriterSvg.Format = BarcodeFormat.CODE_128;
    barcodeWriterSvg.Options.GS1Format = true;
    barcodeWriterSvg.Options.Margin = 64;
    
    var svgImage = barcodeWriterSvg.Write(content);
    return svgImage.Content;
    

    但原来的解决方案是基于手动将FNC1字符添加到字符串https://github.com/micjahn/ZXing.Net/wiki/Generating-GS1-DataMatrix-and-GS1-Code128-barcodes的开头

    【讨论】:

    • 目前选项 GS1Format 仅用于二维码编码器。它只在第一个位置添加了 GS1 格式标识符 FNC1。没有添加组分隔符或类似的控制字符。
    猜你喜欢
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2019-01-29
    • 2016-03-06
    • 2016-09-13
    • 2012-10-19
    相关资源
    最近更新 更多