如何创建1D和线性条形码
IronBarcode 使您能够使用简单的 C# 代码生成所有主要的一维条形码格式,包括 Code 128、GS1-128、Code 39、Code 93、EAN-13、EAN-8、UPC-A、UPC-E、Intelligent Mail、MSI、Codabar 和 DataBar,并具有自动验证和合规性检查功能。 您可以查看支持的条形码格式的完整列表,以找到适合您需求的条形码。
线性条形码仍然是传递信息的行业标准。 它们快速、可靠,几乎可与任何扫描仪配合使用。 由于这些条形码不需要复杂的图像处理,因此在零售收银台和传送带等高速环境中表现出色。
主要的挑战在于根据您的具体需求选择正确的格式。 您可能需要Code128的高数据密度来用于运输标签,EAN8的小巧尺寸适合小型产品,或IntelligentMail Barcode的严格格式用于邮政服务。 IronBarcode 可帮助您高效、可靠地生成所有这些格式。 该库还支持多种输出数据格式,便于与您的现有系统集成。
本指南涵盖如何使用 IronBarcode 生成最重要的一维格式及其常见用例。
快速入门:创建您的第一个1D条码
使用 IronBarcode 的简单 API,从字符串创建 Code128 条形码并将其保存为 JPEG 图像。 马上开始 - 提供数据,选择编码和尺寸,并写入您的图像文件。
-
1使用 IronBarcode 安装 NuGet Package Manager
-
2复制并运行这段代码。
IronBarCode.BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Code128, 250, 100).SaveAsJpeg("MyFirstBarcode.jpg");IronBarCode.BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Code128, 250, 100).SaveAsJpeg("MyFirstBarcode.jpg")IronBarCode.BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Code128, 250, 100).SaveAsJpeg("MyFirstBarcode.jpg") -
3部署到您的生产环境中进行测试
今天就用免费试用在您的项目中开始使用IronBarcode
如何使用 IronBarcode 创建一维和线性条形码
- 下载IronBarcode C#库以创建条形码
- 使用
CreateBarcode生成带有字符串值的条形码 - 使用
BarcodeEncoding指定条形码类型 - 使用
SaveAsJpeg将条形码保存为图像或其他格式
如何创建1D和线性条形码?
线性一维条形码使用可变宽度的条和空白来水平存储数据。 二维条形码(如 QR 码)使用方格网格来保存二维信息。 二维条码可容纳更多数据,如 URL 或联系卡,而一维条码则仅限于简短的字母数字字符串。
这种简洁性可以让一维条形码扫描得更快。 这种结构使条码与标准激光扫描仪普遍兼容,是高速零售和物流环境的理想选择。 在使用大批量扫描应用时,查看我们的读取速度选项以优化性能。
让我们来探讨一下广泛支持的格式以及如何使用 IronBarcode 创建这些格式。
如何创建Code-128条形码?
Code 128 条形码常用于内部物流和运输标签。 它支持全部 128 个字符的 ASCII 范围,能高效地将标准数字和英文文本压缩到较小的空间内。 这使得 Code 128 成为仓库管理系统和库存跟踪的理想选择,因为在这些系统中,空间有限,但数据密度至关重要。
然而,在没有额外扩展的情况下,它无法原生支持 Unicode 或非拉丁字符。 它无法处理中文或阿拉伯语等语言的复杂字符,会误解数据,导致错误输出。 对于需要Unicode支持的应用,请参阅我们的书写Unicode条形码指南。
我需要什么代码?
IronBarcode 使生成 Code-128 简单明了:将BarcodeEncoding.Code128作为第二个参数传递给Create方法,然后导出为图像。 了解更多有关创建条形码图像的各种格式和选项。
using IronBarCode;
// Specify Code 128 Format
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128);
// Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg");using IronBarCode;
// Specify Code 128 Format
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128);
// Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg");Imports IronBarCode
' Specify Code 128 Format
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128)
' Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg")Imports IronBarCode
' Specify Code 128 Format
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.Code128)
' Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save it as JPG
barcode.SaveAsJpeg("code128-sample.jpg")输出是什么样的?

如何创建GSI-128条形码?
GS1-128 是在 Code 128 基础上应用的一种附加数据格式。GS1-128 的主要优点是全球数据解释一致,消除了误解和歧义。 这种标准化对于产品在不同公司和国家之间流动的供应链管理至关重要。
但是,由于格式要求严格,缺少隐藏控制字符或字段长度不正确都会导致条形码不合规。 如果您遇到GS1-128格式问题,我们的GS1-128故障排除指南可以帮助解决常见问题。
GSI-128需要什么格式?
条形码扫描器使用应用标识符(AI) - 识别产品代码信息的数字前缀。 了解这些标识符对于创建适用于全球供应链的合规条形码至关重要。
GS1-128 遵循由四个部分组成的数据结构:
(数字前缀01)GTIN(全球贸易项目编号): 识别产品是什么的唯一产品ID。 必须是准确的 14 位数字。 如果您的产品代码较短,请填充前导零。 例如,123456789012变为00123456789012。
(数字前缀10)批号/批次: 产品的批号或批次号。 1 至 20 个字母数字字符。 当放置在条形码中间时,需要使用 FNC1 分隔符,以便扫描仪知道其结束位置。 如果在条形码末端,则无需分隔符。
(数字前缀17)到期日期: 产品的到期日期。 按照 YYMMDD 格式固定为六位数。 例如,251231 是 2025 年 12 月 31 日。使用两位数年份,世纪采用滑动窗口。
(数字前缀21)序列号: 识别唯一个体单位的产品序列号。 长度可变,包含 1-20 个字母数字字符。
如何使用IronBarcode生成GSI-128?
生成 GS1-128 条形码非常简单; 将BarcodeEncoding.Code128GS1作为第二个参数传递给Create。
下面的示例显示了一个符合 GS1-128 标准的完整值,包含所有四个属性,并将其导出为图像。
using IronBarCode;
// Valid GS1-128 String: GTIN + Expiry + Batch + Serial Number
string gs1Value = "(01)01234567890128(17)251231(10)BATCH001(21)111111";
// Create the barcode
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(gs1Value, BarcodeEncoding.Code128GS1);
// Display the value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("gsi128-sample.jpg");using IronBarCode;
// Valid GS1-128 String: GTIN + Expiry + Batch + Serial Number
string gs1Value = "(01)01234567890128(17)251231(10)BATCH001(21)111111";
// Create the barcode
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(gs1Value, BarcodeEncoding.Code128GS1);
// Display the value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("gsi128-sample.jpg");Imports IronBarCode
' Valid GS1-128 String: GTIN + Expiry + Batch + Serial Number
Dim gs1Value As String = "(01)01234567890128(17)251231(10)BATCH001(21)111111"
' Create the barcode
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(gs1Value, BarcodeEncoding.Code128GS1)
' Display the value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("gsi128-sample.jpg")Imports IronBarCode
' Valid GS1-128 String: GTIN + Expiry + Batch + Serial Number
Dim gs1Value As String = "(01)01234567890128(17)251231(10)BATCH001(21)111111"
' Create the barcode
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(gs1Value, BarcodeEncoding.Code128GS1)
' Display the value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("gsi128-sample.jpg")GSI-128输出是什么样的?

如何修复GSI-128格式错误?
如果您的字符串不符合 GS1-128 标准,IronBarcode 会抛出异常。 使用上表验证字符串值,并进行相应修改。

如何创建Code 39条形码?
Code 39 是最早的字母数字条形码标准之一,以可靠性著称。 常见于汽车和国防领域。 它能够对字母和数字进行编码,而不需要校验位,因此对于通过其他方式验证数据完整性的环境来说非常简单。
然而,Code 39 的字符集有限。 它只允许大写英文字符、数字和符号,如/、.、-等。标准模式不支持小写。 有关读取标准和扩展Code 39条形码的信息,请参阅我们的Code 39读取指南。
我需要什么Code 39代码?
要生成 Code39,请将BarcodeEncoding.Code39作为第二个参数传递给Create。
下面是一个例子:
using IronBarCode;
// Specify Code39 Format
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("IRON-1234", BarcodeEncoding.Code39);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("code39.jpg");using IronBarCode;
// Specify Code39 Format
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("IRON-1234", BarcodeEncoding.Code39);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("code39.jpg");Imports IronBarCode
' Specify Code39 Format
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("IRON-1234", BarcodeEncoding.Code39)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("code39.jpg")Imports IronBarCode
' Specify Code39 Format
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("IRON-1234", BarcodeEncoding.Code39)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("code39.jpg")Code 39输出是什么样的?

为什么我会遇到Code 39错误?

如果字符串不符合 Code39 标准,IronBarcode 会抛出此异常。
。
如何创建Code 93条形码?
Code 93 是对 Code 39 的改进,常用于空间有限但需要字母数字数据的物流和电子元件标签中。 改进后的密度适合空间有限的小型电子元件。
它接受完整的 ASCII 字符、大写英文字母、数字和符号。 提供比 Code 39 更高的密度。
我需要什么Code 93代码?
要生成 Code93,请将BarcodeEncoding.Code93作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: Uppercase A-Z, 0-9, specific symbols
string code93Value = "ELEC-COMP-99";
// Create Code 93
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(code93Value, BarcodeWriterEncoding.Code93);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("code93.jpg");using IronBarCode;
// Valid Input: Uppercase A-Z, 0-9, specific symbols
string code93Value = "ELEC-COMP-99";
// Create Code 93
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(code93Value, BarcodeWriterEncoding.Code93);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("code93.jpg");Imports IronBarCode
' Valid Input: Uppercase A-Z, 0-9, specific symbols
Dim code93Value As String = "ELEC-COMP-99"
' Create Code 93
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(code93Value, BarcodeWriterEncoding.Code93)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("code93.jpg")Imports IronBarCode
' Valid Input: Uppercase A-Z, 0-9, specific symbols
Dim code93Value As String = "ELEC-COMP-99"
' Create Code 93
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(code93Value, BarcodeWriterEncoding.Code93)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("code93.jpg")Code 93输出是什么样的?

如何创建CodaBar条形码?
Codabar在印刷质量欠佳时依然可靠,广泛用于血库和图书馆。 格式的容错性非常适合低质量打印机或磨损的情况。
长度可变,但字符集有限。 仅包含数字(0-9)和符号(-, $, :, /, ., +)。 开始/停止字符 A、B、C、D 表示开始或结束。 这些字符不能出现在条形码中间。
我需要什么CodaBar代码?
要生成 Codabar,请将BarcodeEncoding.Codabar作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: Numbers 0-9 and symbols -$:/.+ IronBarcode automatically appends by A, B, C, or D
string codabarValue = "10500200";
// Create Codabar
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(codabarValue, BarcodeWriterEncoding.Codabar);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("codabar.jpg");using IronBarCode;
// Valid Input: Numbers 0-9 and symbols -$:/.+ IronBarcode automatically appends by A, B, C, or D
string codabarValue = "10500200";
// Create Codabar
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(codabarValue, BarcodeWriterEncoding.Codabar);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("codabar.jpg");Imports IronBarCode
' Valid Input: Numbers 0-9 and symbols -$:/.+ IronBarcode automatically appends by A, B, C, or D
Dim codabarValue As String = "10500200"
' Create Codabar
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(codabarValue, BarcodeWriterEncoding.Codabar)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("codabar.jpg")Imports IronBarCode
' Valid Input: Numbers 0-9 and symbols -$:/.+ IronBarcode automatically appends by A, B, C, or D
Dim codabarValue As String = "10500200"
' Create Codabar
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(codabarValue, BarcodeWriterEncoding.Codabar)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("codabar.jpg")CodaBar输出是什么样的?

为什么CodaBar会出现错误?
如果输入包含字母,IronBarcode 会出现异常,说明它只接受数值。

如何创建DataBar条形码?
GS1 DataBar(原 RSS-14)更为紧凑,专为产品标识号而设计。 适用于新鲜农产品等小件物品,因为传统的条形码占用太多空间。 了解更多关于新格式功能的内容请查看我们的新格式里程碑更新。
与 GS1-128 一样,它也有严格的编码格式。 全向变体仅包含产品代码属性。
GS1-DataBar需要什么格式?
(数字前缀-01)GTIN(全球贸易项目编号): 唯一产品ID。 必须是准确的 14 位数字。
如何生成GS1 DataBar代码?
要生成 GS1 DataBar,请将BarcodeWriterEncoding.DataBar作为第二个参数传递给CreateBarcode:
using IronBarCode;
// Valid Input: Exactly 14 digits (GTIN). IronBarcode will calculate and append the correct check digit
string databarValue = "0123456789012";
// Create GS1 DataBar
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(databarValue, BarcodeWriterEncoding.DataBar);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("databar.jpg");using IronBarCode;
// Valid Input: Exactly 14 digits (GTIN). IronBarcode will calculate and append the correct check digit
string databarValue = "0123456789012";
// Create GS1 DataBar
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(databarValue, BarcodeWriterEncoding.DataBar);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("databar.jpg");Imports IronBarCode
' Valid Input: Exactly 14 digits (GTIN). IronBarcode will calculate and append the correct check digit
Dim databarValue As String = "0123456789012"
' Create GS1 DataBar
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(databarValue, BarcodeWriterEncoding.DataBar)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("databar.jpg")Imports IronBarCode
' Valid Input: Exactly 14 digits (GTIN). IronBarcode will calculate and append the correct check digit
Dim databarValue As String = "0123456789012"
' Create GS1 DataBar
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(databarValue, BarcodeWriterEncoding.DataBar)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("databar.jpg")DataBar输出是什么样的?

如何创建EAN-13条形码?
EAN-13是全球用于消费产品的标准零售条形码 - 这是最广泛使用的格式之一。 对于零售应用,探索如何定制条形码样式以符合品牌要求。
EAN-13 需要严格的授权。 如果没有获得 GS1 公司前缀许可,您就无法生成供公众使用的 EAN-13 编号,以确保条形码的唯一性。 仅包含 13 位数字。 有关许可信息,请访问我们的许可页面。
EAN-13 有特定的格式规则。
EAN-13需要什么格式?
EAN-13 条形码由四部分组成:
GS1前缀(前三位): 识别GS1会员组织,通常为注册国家。 举例说明:000-019(美国/加拿大 - UPC 兼容)、500-509(英国)、450-459(日本)。
制造商代码: 由GS1分配的可变长度代码。
产品代码: 由制造商分配给特定物品。
校验码(最后一位): 使用模10算法从前12位计算得出。 确保扫描仪读取准确。
如何生成EAN-13代码?
要生成 EAN-13,请将BarcodeEncoding.EAN13作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: 12 digits (library calculates 13th check digit) or full 13 digits.
string ean13Value = "4006381333931";
// Create EAN-13
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(ean13Value, BarcodeWriterEncoding.EAN13);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("ean13.jpg");using IronBarCode;
// Valid Input: 12 digits (library calculates 13th check digit) or full 13 digits.
string ean13Value = "4006381333931";
// Create EAN-13
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(ean13Value, BarcodeWriterEncoding.EAN13);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("ean13.jpg");Imports IronBarCode
' Valid Input: 12 digits (library calculates 13th check digit) or full 13 digits.
Dim ean13Value As String = "4006381333931"
' Create EAN-13
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(ean13Value, BarcodeWriterEncoding.EAN13)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("ean13.jpg")Imports IronBarCode
' Valid Input: 12 digits (library calculates 13th check digit) or full 13 digits.
Dim ean13Value As String = "4006381333931"
' Create EAN-13
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(ean13Value, BarcodeWriterEncoding.EAN13)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("ean13.jpg")EAN-13输出是什么样的?

如何修复EAN-13格式错误?
IronBarcode 对于非数值会出现异常。

如何创建EAN-8条形码?
EAN-8 是 EAN-13 的精简版,适用于全尺寸条形码占用空间过大的小型消费品。 常见于包装空间有限的铅笔和化妆品上。
与 Code 128 或 Code 39 不同,EAN-8 使用特定分配的前缀,而不是任意数字。
EAN-8 使用严格的 8 位数格式:7 个数据位和 1 个校验位。 仅限数字。
我需要什么EAN-8代码?
创建 EAN-8 需要将BarcodeEncoding.EAN8传递给使用Create的第二个参数:
using IronBarCode;
// Valid Input: 7 digits (library calculates 8th check digit).
string ean8Value = "1234567";
// Create EAN-8
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(ean8Value, BarcodeWriterEncoding.EAN8);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("ean8.jpg");using IronBarCode;
// Valid Input: 7 digits (library calculates 8th check digit).
string ean8Value = "1234567";
// Create EAN-8
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(ean8Value, BarcodeWriterEncoding.EAN8);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("ean8.jpg");Imports IronBarCode
' Valid Input: 7 digits (library calculates 8th check digit).
Dim ean8Value As String = "1234567"
' Create EAN-8
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(ean8Value, BarcodeWriterEncoding.EAN8)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("ean8.jpg")Imports IronBarCode
' Valid Input: 7 digits (library calculates 8th check digit).
Dim ean8Value As String = "1234567"
' Create EAN-8
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(ean8Value, BarcodeWriterEncoding.EAN8)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("ean8.jpg")EAN-8输出是什么样的?

为何我会遇到EAN-8长度错误?
如果输入包含 8 个以上数字字符,IronBarcode 会出现异常,说明 EAN-8 需要 8 个字符。

如何创建智能邮件条形码?
智能邮件条形码 (IMB) 是美国邮政的邮件自动分拣和跟踪标准。 与传统的宽度调制条形码不同,IMB 使用高度调制条形码。 信函和大尺寸扁平邮件必须使用此格式才能享受自动分拣资费优惠。 仅支持特定的数字长度:20、25、29 或 31 位。
使用特定的数字前缀来定义信息。
智能邮件需要什么格式?
(前2位)条形码ID: 条形码标识符。 严格限制 2 位数字。 通常 00 用于标准商业邮件。
(接下来的3位)服务类型ID(STID): 定义邮件类别(如,第一类邮件,营销邮件)和服务(如,地址更正,跟踪)。 对邮政折扣至关重要。
(接下来的6或9位)发件人ID(MID): 邮件发送公司由USPS分配的6或9位数字。
(接下来的6或9位)序列号: 识别唯一的单独邮件。
(最后0、5、9或11位)路由代码: 投递ZIP邮政编码。
如何生成智能邮件代码?
要生成 IMB,请将BarcodeEncoding.IntelligentMail作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: 20, 25, 29, or 31 digits.
// Format: Barcode ID(2) + Service(3) + Mailer ID(6/9) + Serial(9/6) + Routing Zip(0/5/9/11)
string imbValue = "00270123456200800001";
// Create Intelligent Mail
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(imbValue, BarcodeWriterEncoding.IntelligentMail);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("imb.jpg");using IronBarCode;
// Valid Input: 20, 25, 29, or 31 digits.
// Format: Barcode ID(2) + Service(3) + Mailer ID(6/9) + Serial(9/6) + Routing Zip(0/5/9/11)
string imbValue = "00270123456200800001";
// Create Intelligent Mail
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(imbValue, BarcodeWriterEncoding.IntelligentMail);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("imb.jpg");Imports IronBarCode
' Valid Input: 20, 25, 29, or 31 digits.
' Format: Barcode ID(2) + Service(3) + Mailer ID(6/9) + Serial(9/6) + Routing Zip(0/5/9/11)
Dim imbValue As String = "00270123456200800001"
' Create Intelligent Mail
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(imbValue, BarcodeWriterEncoding.IntelligentMail)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("imb.jpg")Imports IronBarCode
' Valid Input: 20, 25, 29, or 31 digits.
' Format: Barcode ID(2) + Service(3) + Mailer ID(6/9) + Serial(9/6) + Routing Zip(0/5/9/11)
Dim imbValue As String = "00270123456200800001"
' Create Intelligent Mail
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(imbValue, BarcodeWriterEncoding.IntelligentMail)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("imb.jpg")智能邮件输出是什么样的?

如何修复智能邮件格式错误?
如果格式不正确,IronBarcode 会抛出异常。 根据上述格式验证字符串值,修改后重试。

如何创建MSI条形码?
MSI 常见于零售货架标签和仓库库存控制,很少用于消费品。 它的简单性和可靠性使其在内部操作中很受欢迎。 对于MSI识别问题,查看我们的MSI条形码故障排除指南。
MSI 仅限数字; 不允许使用字母或符号。 长度不定,通常为 10-15 位数。
我需要什么MSI代码?
要生成 MSI,请将BarcodeEncoding.MSI作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: Numeric digits only. Variable length.
string msiValue = "1234567890";
// Create MSI
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(msiValue, BarcodeWriterEncoding.MSI);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("msi.jpg");using IronBarCode;
// Valid Input: Numeric digits only. Variable length.
string msiValue = "1234567890";
// Create MSI
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(msiValue, BarcodeWriterEncoding.MSI);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("msi.jpg");Imports IronBarCode
' Valid Input: Numeric digits only. Variable length.
Dim msiValue As String = "1234567890"
' Create MSI
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(msiValue, BarcodeWriterEncoding.MSI)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("msi.jpg")Imports IronBarCode
' Valid Input: Numeric digits only. Variable length.
Dim msiValue As String = "1234567890"
' Create MSI
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(msiValue, BarcodeWriterEncoding.MSI)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("msi.jpg")MSI输出是什么样的?

如何创建UPC-A条形码?
UPC-A 是美国和加拿大的标准零售条形码。 EAN-13 的 12 位数子集。最常见于北美超市的产品上。 由于这些工具被广泛采用,因此对北美市场至关重要。
与 EAN-13 类似,通常是分配而不是生成。
UPC-A 包含 12 位数字。 不接受字母。
UPC-A需要什么格式?
数字系统字符(1): 识别产品类型(0、1、6、7、8用于标准零售; 2 用于变重商品;3 用于药品;5 用于优惠券)。
制造商代码(5): 由GS1分配。
产品代码(5): 由制造商分配。
校验码(1): 使用模10校验和计算得出。
如何生成UPC-A代码?
要生成 UPC-A,请将BarcodeEncoding.UPCA作为第二个参数传递给Create:
using IronBarCode;
// Valid Input: 11 digits (library calculates 12th check digit) or full 12 digits
string upcaValue = "01234567890";
// Create UPC-A
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(upcaValue, BarcodeWriterEncoding.UPCA);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG
barcode.SaveAsJpeg("upca.jpg");using IronBarCode;
// Valid Input: 11 digits (library calculates 12th check digit) or full 12 digits
string upcaValue = "01234567890";
// Create UPC-A
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(upcaValue, BarcodeWriterEncoding.UPCA);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG
barcode.SaveAsJpeg("upca.jpg");Imports IronBarCode
' Valid Input: 11 digits (library calculates 12th check digit) or full 12 digits
Dim upcaValue As String = "01234567890"
' Create UPC-A
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(upcaValue, BarcodeWriterEncoding.UPCA)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG
barcode.SaveAsJpeg("upca.jpg")Imports IronBarCode
' Valid Input: 11 digits (library calculates 12th check digit) or full 12 digits
Dim upcaValue As String = "01234567890"
' Create UPC-A
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(upcaValue, BarcodeWriterEncoding.UPCA)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG
barcode.SaveAsJpeg("upca.jpg")UPC-A输出是什么样的?

为何我遇到UPC-A长度错误?
如果数值长度超过 13,IronBarcode 就会出错。

如何创建UPC-E条形码?
UPC-E 是紧凑型 UPC-A 版本,适用于汽水罐等小型零售包装,因为完整的 12 位 UPC-A 尺寸太大。 压缩算法以大约一半的空间编码相同的信息。
与 UPC-A 一样,严格使用数字。 不接受字母或符号。
我需要什么UPC-E代码?
要生成 UPC-E,请将BarcodeEncoding.UPCE作为第二个参数传递给Create:
using IronBarCode;
// Valid input: 8 digits or less in which the last digit is a check digit
// IronBarcode automatically calculates the check digit if only 7 digits are provided.
string upceValue = "0123456";
// Create UPC-E
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(upceValue, BarcodeWriterEncoding.UPCE);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("upce.jpg");using IronBarCode;
// Valid input: 8 digits or less in which the last digit is a check digit
// IronBarcode automatically calculates the check digit if only 7 digits are provided.
string upceValue = "0123456";
// Create UPC-E
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(upceValue, BarcodeWriterEncoding.UPCE);
// Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode();
// Save as a JPG file
barcode.SaveAsJpeg("upce.jpg");Imports IronBarCode
' Valid input: 8 digits or less in which the last digit is a check digit
' IronBarcode automatically calculates the check digit if only 7 digits are provided.
Dim upceValue As String = "0123456"
' Create UPC-E
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(upceValue, BarcodeWriterEncoding.UPCE)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("upce.jpg")Imports IronBarCode
' Valid input: 8 digits or less in which the last digit is a check digit
' IronBarcode automatically calculates the check digit if only 7 digits are provided.
Dim upceValue As String = "0123456"
' Create UPC-E
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(upceValue, BarcodeWriterEncoding.UPCE)
' Stamp barcode value below the barcode
barcode.AddBarcodeValueTextBelowBarcode()
' Save as a JPG file
barcode.SaveAsJpeg("upce.jpg")UPC-E输出是什么样的?

如何修复UPC-E长度错误?
如果数字位数超过 8,IronBarcode 就会出错。

不同的1D条形码类型有哪些?
| 名称 | 格式 | 常见用法 | 限制与陷阱 |
|---|---|---|---|
| Code 128 | 字母数字 支持完整的 ASCII 128 字符集。长度可变。高密度。 | 内部物流、运输标签、资产跟踪、身份证。 |
|
| GS1-128 | 结构化字母数字 以 FNC1 开头并带有应用标识符(例如 (01))的 Code 128。 | 全球供应链(沃尔玛/亚马逊)、托盘标签、EDI。 |
|
| Code 39 | 字母数字(受限) 大写字母 A-Z、数字 0-9 以及 -. $ / + % space。 | 汽车 (AIAG)、国防 (LOGMARS)、传统工业 ID。 |
|
| Code 93 | 字母数字 与 Code 39 类似,但密度更高。 | 电子产品(PCB)、加拿大邮政和内部制造。 |
|
| Codabar | 数字 + 符号 0-9 以及 - $ : /. +。起始/终止符:A、B、C、D。 | 血库、图书馆、联邦快递空运单(传统)。 |
|
| GS1 DataBar | 数字(14 位) 仅编码 GTIN-14。极其紧凑。 | 松散的农产品(水果贴纸)、小型化妆品和保健品瓶。 |
|
| EAN-13 | 数字(13 位) 国家代码 + 厂商代码 + 产品代码 + 校验位。 | 全球零售销售点(超市)。 |
|
| EAN-8 | 数字(8 位) 7 位数据 + 1 位校验位。 | 微小的零售包装(口香糖、铅笔)。 |
|
| Intelligent Mail | 数字(20、25、29、31 位) 高度调制(四态)条。 | USPS 邮件分拣与自动化。 |
|
| MSI(Plessey) | 仅数字 长度可变。 | 零售货架标签、仓库货位箱。 |
|
| UPC-A | 数字(12 位) 11 位数据 + 1 位校验位。 | 北美零售销售点。 |
|
| UPC-E | 数字(6 位) 压缩格式。 | 美国/加拿大的小型零售包装(苏打水罐)。 |
|
常见问题
使用IronBarcode在C#中创建1D条形码的主要好处是什么?
IronBarcode提供简单的API来生成各种1D条形码格式,如Code 128、EAN-13和UPC-A,并具备自动验证和合规检查功能,使其成为C#应用程序中高效且可靠的条形码生成工具。
如何使用IronBarcode创建条形码?
您可以通过使用BarcodeWriter.CreateBarcode方法,提供数据,选择条形码编码类型,然后将其保存为JPEG等图像格式来创建条形码。
我应该使用什么格式与IronBarcode生成运输标签条形码?
对于运输标签,由于其数据密度较高,建议使用Code 128,这使其适合于空间有限的地方,同时可以编码大量字符。
IronBarcode能否处理1D条形码中的Unicode或非拉丁字符?
IronBarcode本身支持格式如Code 128中的完整128字符ASCII范围,但需要附加功能来支持Unicode或特殊字符,这对于中文或阿拉伯语等语言是必需的。
UPC-A和UPC-E条形码有什么区别?
UPC-A是北美零售中常用的12位条形码,而UPC-E是更紧凑的6位版本,适用于如苏打罐般的空间有限的包装,使用压缩算法来适应有限空间。
使用IronBarcode生成EAN-13条形码的规定是什么?
EAN-13条形码需要具有特定前缀的13位格式,以识别GS1成员组织和产品代码。它们必须遵守与GS1的许可协议,以确保全球唯一标识符的使用。
如何解决GS1-128条形码的格式错误?
确保您的条形码字符串符合GS1-128标准,以FNC1字符开头,并正确格式化应用标识符。IronBarcode会通过抛出异常来帮助解决不符合标准的字符串,您可以使用GS1-128故障排除指南来解决这些问题。
是什么使Code 39适合汽车行业?
Code 39在汽车行业中受欢迎,因为它能够在不需要校验位的情况下编码字母数字数据,简化了数据完整性通过其他手段验证的环境。
IronBarcode如何处理不同的输出格式?
IronBarcode允许您将生成的条形码保存为各种输出格式如JPEG,通过灵活的导出选项,确保与现有系统的轻松集成。
为什么在USPS应用中要使用智能邮件条形码?
智能邮件条形码是USPS的标准,优化了邮件分类并实现了追踪,要求特定的数字长度以确保合规并有资格享受邮资折扣。
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。