如何建立1D和線性條碼

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcode使您能夠生成所有主要的1D條碼格式,包括Code 128、GS1-128、Code 39、Code 93、EAN-13、EAN-8、UPC-A、UPC-E、智能郵件、MSI、Codabar和DataBar,使用簡單的C#程式碼進行自動驗證和合規檢查。 您可以瀏覽支持的條碼格式完整列表,以找到適合您需求的格式。

線性條碼仍然是傳遞資訊的行業標準。 它們快速、可靠,幾乎可以與任何掃描器一起使用。 由於這些條碼不需要複雜的圖像處理,它們在零售結帳和傳送帶等高速環境中表現出色。

主要挑戰是為您的特定需求選擇正確的格式。 您可能需要IntelligentMail Barcode的嚴格格式來用於郵政服務。 IronBarcode幫助您高效可靠地生成所有這些格式。 該程式庫還支持多種輸出資料格式,以便與您現有系統無縫整合。

本指南涵蓋如何使用IronBarcode生成最關鍵的1D格式及其常見用例。


快速入門:建立您的第一個1D條碼

使用IronBarcode的簡單API從字串建立Code128條碼並將其儲存為JPEG圖像。 立即開始——提供資料,選擇編碼和尺寸,並寫入圖像檔案。

  1. 使用NuGet套件管理器安裝https://www.nuget.org/packages/BarCode

    PM > Install-Package BarCode
  2. 複製並運行這段程式碼片段。

    IronBarCode.BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Code128, 250, 100).SaveAsJpeg("MyFirstBarcode.jpg");
  3. 部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronBarcode,透過免費試用

    arrow pointer

如何建立1D和線性條碼?

線性一維條碼使用可變寬度的線和空間以水平方向儲存資料。 像QR程式碼的二維條碼使用方塊網格以二維方式儲存資訊。 雖然二維程式碼能容納更多資料,比如URL或聯絡卡片,但一維條碼限制於短的字母數字串。

這種簡潔性允許一維條碼更快速地掃描。 它使標準激光掃描器可以普遍相容,使其適合高速零售和物流環境。 在處理高容量掃描應用時,探索我們的讀取速度選項以優化性能。

讓我們來探索最支持的格式以及如何使用IronBarcode建立它們。

如何建立Code-128條碼?

Code 128條碼常用於內部物流和運送標籤。 它支持完整的128個ASCII字元範圍,使其在壓縮標準數字和英語文字到小空間時非常高效。 這使Code 128成為倉儲管理系統和庫存追蹤的理想選擇,其中空間有限但資料密度至關重要。

然而,它不原生支持Unicode或非拉丁字元,除非有額外擴展。 它無法處理來自中文或阿拉伯語等語言的複雜字元,會誤解資料,導致輸出錯誤。 對於需要Unicode支持的應用,請參閱我們的寫入Unicode條碼指南。

我需要什麼程式碼?

IronBarcode使生成Code-128很簡單:在調用BarcodeEncoding.Code128作為第二個參數傳遞,然後導出為圖像。 了解更多關於建立條碼圖像的各種格式和選項。

:path=/static-assets/barcode/content-code-examples/how-to/create-code-128-barcode.cs
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")
$vbLabelText   $csharpLabel

輸出是什麼樣子的?

Code-128範例輸出

如何建立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個字母數字字元。

請注意僅GTIN是必需的; 批次、到期和序列屬性是可選的.

警告雖然僅需GTIN,但一些零售商制定了特定的合規指南。 建立條碼時請檢查其要求.

如何使用IronBarcode生成GSI-128?

生成GS1-128條碼很簡單; 在調用BarcodeEncoding.Code128GS1作為第二個參數傳遞。

下面的例子展示了一個完整的GS1-128合規值,包含所有四個屬性,並將其導出為圖像。

請注意每個數字前綴所需的括弧不可缺少,否則該部分不會被識別為有效屬性。

請注意IronBarcode在建立GSI-128時會自動插入FNC1分隔符。

:path=/static-assets/barcode/content-code-examples/how-to/create-gsi-128-barcode.cs
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")
$vbLabelText   $csharpLabel

GSI-128輸出是什麼樣子的?

GS1-128範例輸出

如何修復GSI-128格式錯誤?

如果您的字串不符合GS1-128標準,IronBarcode會拋出異常。 使用上表核實您的字串值並做相應修改。

GS1-128異常

如何建立Code 39條碼?

Code 39是最早的字母數字條碼標準之一,以可靠性著稱。 常見於汽車和國防部門。 其編碼字母和數字的能力不需要校驗數字,使其在資料完整性通過其他手段驗證的環境中非常簡單。

然而,Code 39有一個有限的字元集。 它只允許大寫英文字母、數字和像/、.、-等符號。標準模式不支持小寫。 關於閱讀標準和擴展Code 39條碼的資訊,請參見我們的Code 39閱讀指南

Code 39需要什麼程式碼?

要生成Code39,在使用BarcodeEncoding.Code39作為第二個參數傳遞。

以下是一個例子:

:path=/static-assets/barcode/content-code-examples/how-to/create-code-39-barcode.cs
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")
$vbLabelText   $csharpLabel

Code 39輸出是什麼樣子的?

Code39範例輸出

為何會出現Code 39錯誤?

Code39異常

如果字串不符合Code39標準,IronBarcode將拋出此異常。

警告IronBarcode目前不支持生成擴展Code39條碼; 僅支持閱讀。 關於閱讀擴展和標準Code39,請參見我們的Code 39閱讀教程
. )}]

如何建立Code 93條碼?

Code 93改進了Code 39,常用於空間有限但需要字母資料的物流和電子元件標籤。 提高的密度適合空間有限的小電子元件。

它接受完整的ASCII字元、大寫英文字元、數字和符號。 比Code 39提供更高的密度。

生成Code 93需要的程式碼?

要生成Code93,在使用BarcodeEncoding.Code93作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-code-93-barcode.cs
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")
$vbLabelText   $csharpLabel

Code 93輸出是什麼樣子的?

Code93範例輸出

如何建立CodaBar條碼?

Codabar對於印刷質量差的情況具有強大的抗干擾性,廣泛應用於血庫和圖書館。 該格式的容錯能力為低質量印表機或損耗的應對提供了理想選擇。

變長但字元集有限。 只包含數字(0-9)和符號(-, $, :, /, ., +)。 起始/停止字元A,B,C,D表示開始或結束。 這些字元不能出現在條碼中間。

生成CodaBar需要什麼程式碼?

要生成Codabar,在使用BarcodeEncoding.Codabar作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-codabar-barcode.cs
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")
$vbLabelText   $csharpLabel

CodaBar輸出是什麼樣子的?

Codabar範例輸出

為什麼CodaBar拋出錯誤?

如果輸入包含字母,IronBarcode會拋出一個異常,表示它只接受數字值。

Codabar異常

如何建立DataBar條碼?

GS1 DataBar(以前的RSS-14)更加緊湊,專為產品識別號碼設計。 適用於小件物品如新鮮農產品,傳統條碼佔用太多空間。 在我們的新格式里程碑更新中了解更多有關新格式功能的資訊。

類似於GS1-128,它具有嚴格的編碼格式。 全方向變體僅含有產品程式碼屬性。

GS1-DataBar需要什麼格式?

(數字前綴-01)GTIN(全球貿易項目編號):唯一的產品ID。 必須正好14個數字。

警告標準"GS1 DataBar全方向"只能包含GTIN(01)。 使用GS1 DataBar擴展版以獲得額外屬性。

如何生成GS1 DataBar程式碼?

要生成GS1 DataBar,在使用BarcodeEncoding.DataBar作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-gs1-databar-barcode.cs
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")
$vbLabelText   $csharpLabel

DataBar輸出是什麼樣子的?

GS1-Databar範例輸出

如何建立EAN-13條碼?

EAN-13是全球零售條碼標準,廣泛用於消費品——是使用最廣的格式之一。 對於零售應用,探索如何定制條碼樣式以符合品牌要求。

EAN-13需要嚴格的許可。 您不能在沒有為公共使用許可的情況下生成EAN-13號碼,這需要許可一個GS1公司前綴以確保條碼的唯一性。 只包含13個數字。 關於許可資訊,請存取我們的許可頁面

EAN-13有具體格式規則。

EAN-13需要什麼格式?

EAN-13條碼分為四個部分:

GS1前綴(前三位數字):識別GS1成員組織,通常為註冊國家。 範例:000-019(美國/加拿大 - UPC相容),500-509(英國),450-459(日本)。

製造商程式碼:GS1分配的可變長度程式碼。

產品程式碼:由製造商分配給特定產品的程式碼。

校驗位(最後一位):使用模10算法從前12個數字計算出來的。 確保掃描器的準確讀取。

警告前綴200-299保留作為限流使用。 生成EAN-13條碼時請勿在生產中使用這些前綴.

如何生成EAN-13程式碼?

要生成EAN-13,在使用BarcodeEncoding.EAN13作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-ean13-barcode.cs
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")
$vbLabelText   $csharpLabel

EAN-13輸出是什麼樣子的?

EAN-13範例輸出

如何修復EAN-13格式錯誤?

對於非數字值,IronBarcode會拋出異常。

EAN-13故障排除

如何建立EAN-8條碼?

EAN-8是小型消費者產品的壓縮EAN-13版本,因為全尺寸條碼佔用太多空間。 常見於鉛筆和化妝品上,包裝空間有限。

與Code 128或Code 39不同,EAN-8使用特定的分配前綴,而非任意數字。

EAN-8使用嚴格的8位數字格式:7個資料數字和1個校驗數字。 僅限數字。

EAN-8需要什麼程式碼?

建立EAN-8需要在使用BarcodeEncoding.EAN8作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-ean8-barcode.cs
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")
$vbLabelText   $csharpLabel

EAN-8輸出是什麼樣子的?

EAN-8範例輸出

為何會出現EAN-8長度錯誤?

如果輸入包含8個以上的數字,IronBarcode 會拋出異常,指出EAN-8需要8個字元。

EAN-8異常

如何建立智能郵件條碼?

智能郵件條碼(IMB)是美國郵政的自動化信件分揀和追踪標準。 與傳統的寬度調製條碼不同,IMB使用高度調制的條。 信件和大信件自動化價格折扣的必需條件。 僅支持特定的數字長度:20、25、29或31位。

使用特定的數字前綴來定義資訊。

智能郵件需要什麼格式?

(前兩位數字)條碼ID:條碼標識符。 嚴格地是2個數字。 通常是標準商業郵件的00。

(下三位數字)服務型別ID(STID):定義郵件類別(如一類郵件、營銷郵件)和服務(如地址校正、追蹤)。 對於郵政折扣至關重要。

(下六或九位數字)郵寄商ID(MID):由美國郵政分配給公司的6位或9位數字。

(下六或九位數字)序列號:識別唯一的郵件件。

(最後0、5、9或11位數字)路由碼:送達郵政編碼。

如何生成智能郵件程式碼?

要生成IMB,當調用BarcodeEncoding.IntelligentMail作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-imb-barcode.cs
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")
$vbLabelText   $csharpLabel

智能郵件輸出是什麼樣子的?

智能郵件範例輸出

如何修復智能郵件格式錯誤?

如果格式不正確,IronBarcode會拋出異常。 根據上面格式驗證字串值,然後修改後重試。

智能郵件異常

如何建立MSI條碼?

MSI常見於零售貨架標籤和倉庫庫存控制,很少用於消費者產品。 其簡單性和可靠性使其在內部操作中受歡迎。 對於MSI識別問題,請查看我們的MSI條碼故障排除指南

MSI僅限數字; 不允許字母或符號。 可變長度,通常是10至15位數字。

MSI需要什麼程式碼?

要生成MSI,當調用BarcodeEncoding.MSI作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-msi-barcode.cs
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")
$vbLabelText   $csharpLabel

MSI輸出是什麼樣子的?

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作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-upc-a-barcode.cs
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")
$vbLabelText   $csharpLabel

UPC-A輸出是什麼樣子的?

UPC-A範例輸出

為何會出現UPC-A長度錯誤?

如果數字值超過13位,IronBarcode拋出錯誤。

UPC-A異常

如何建立UPC-E條碼?

UPC-E是適用於像蘇打罐等小零售包裝的壓縮UPC-A版本,全12位的UPC-A過大。 壓縮算法將相同資訊編碼為大約一半的空間。

與UPC-A一樣,嚴格限制於數字。 不接受字母或符號。

UPC-E需要什麼程式碼?

要生成UPC-E,當調用BarcodeEncoding.UPCE作為第二個參數傳遞:

:path=/static-assets/barcode/content-code-examples/how-to/create-upc-e-barcode.cs
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")
$vbLabelText   $csharpLabel

UPC-E輸出是什麼樣子的?

UPC-E範例輸出

如何修復UPC-E長度錯誤?

如果數字字元超過8,IronBarcode會拋出錯誤。

UPC-E故障排除

有哪些不同的1D條碼型別?

名稱 格式 常見用法 限制和陷阱
Code 128 字母數字
支持完整ASCII 128。可變長度。高密度。
內部物流、運送標籤、資產追蹤、身份證。
  • 無Unicode: 如果不破壞掃描器的相容性,就無法原生編碼特殊字元(例如中文或表情符號)。
  • 列印質量: 需要高解析度;低解析度的熱列印可能導致可讀性問題。
GS1-128 結構苛刻的字母數字
Code 128帶有領頭的FNC1 + 應用識別位(例如(01))。
全球供應鏈(沃爾瑪/亞馬遜),托盤標籤,EDI。
  • 缺失FNC1:必須以不可見的FNC1字元開頭,否則掃描器會將其讀作原始文字。
  • 括號:不要編碼AIs周圍的();它們僅用於人工讀取。
Code 39 字母數字(有限制)
A-Z大寫,0-9,和-. $ / + % space
汽車(AIAG),國防(LOGMARS),舊工業ID。
  • 無小寫:標準模式如果輸入'a'會失敗。擴展模式支持小寫但需要特定的掃描器配置。
  • 低密度: 生成的條碼非常寬,不適合小標籤。
Code 93 字母數字
類似於Code 39但具有更高的密度。
電子(印刷電路板)、加拿大郵政和內部製造業。
  • 校驗位:需要兩個強制性檢查位(C和K)。不要手動計算這些;讓庫完成。
  • 掃描器支持:通常在掃描器上預設禁用,以防止與Code 39的衝突。
Codabar 數字+符號
0-9和- $ : /. +。開始/結束:A、B、C、D。
血庫,圖書館,聯邦快遞航空運單(遺留)。
  • 短讀:易錯誤,掃描器讀取部分程式碼(例如,從"12345"讀取"123")。
  • 無字母:不能編碼資料字母,僅支持A-D作為分隔符。
GS1 DataBar 數字(14位數字)
僅編碼GTIN-14。極其緊湊。
松散產品(水果貼紙),小型化妝品和保健小瓶。
  • 無屬性:標準全向版本不能包含有效期或批次資料(需要擴展版本)。
  • 嚴格輸入:必須正好14位。
EAN-13 數字(13位數字)
國家+製造商+產品+檢查位。
全球零售銷售點(超市)。
  • 許可:需要付費GS1公司前綴。
  • 受限前綴:前綴200-299僅供店內使用,無法在全球供應鏈中使用。
EAN-8 數字(8位數字)
7個資料位和1個檢查位。
微小的零售包裝(口香糖、鉛筆)。
  • 可用性:難以獲得;GS1僅在產品物理上太小而無法使用EAN-13時發佈這些格式。
  • 輸入長度:必須正好是7或8位數字。
智能郵件 數字(20、25、29、31位)
高度調制(四態)條。
美國郵政信件分揀和自動化。
  • 嚴格長度:輸入必須與美國郵政領域(條碼ID、STID、MID、序列、郵編)完全匹配。
  • STID "234":請勿在生產中使用此範例ID;可能導致信件拒收或折扣損失。
MSI(Plesser) 僅限數字
變長。
零售貨架標籤,倉庫箱子。
  • 校驗和混淆:支持Mod 10、Mod 11、Mod 1010等。您必須精確知道您的掃描器預期的哪一個。
  • 可靠性:與現代程式碼相比,讀取率較差。
UPC-A 數字(12位數字)
11個資料位和1個檢查位。
北美零售銷售點。
  • 區域:主要針對美國/加拿大。全球銷售商應使用EAN-13。
  • 前導零:技術上為以0開頭的EAN-13。
UPC-E 數字(6位數字)
壓縮格式。
美國/加拿大的小型零售包裝(蘇打罐)。
  • 壓縮規則:不能僅"轉換"任何UPC-A。您的號碼必須有特定的零模式才能被壓縮。
  • 數字系統:僅支持數字系統0或1。

常見問題

可以生成哪些型別的1D條碼?

IronBarcode可以生成所有主要的1D條碼格式,包括Code 128、GS1-128、Code 39、Code 93、EAN-13、EAN-8、UPC-A、UPC-E、Intelligent Mail、MSI、Codabar和DataBar。每種格式都適合不同的應用 - 如運輸標籤的Code 128、小產品的EAN-8 和郵政服務的Intelligent Mail條碼。

如何在C#中建立基本的1D條碼?

要使用IronBarcode建立1D條碼,請使用BarcodeWriter.CreateBarcode()方法,並用您的資料字串和使用BarcodeEncoding枚舉指定條碼型別。例如:GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Code128);。

支持以哪些輸出格式保存條碼?

IronBarcode支持將生成的條碼保存為多種格式,包括JPEG、PNG和PDF。 您可以使用例如SaveAsJpeg()、SaveAsPng()或其他SaveAs方法將條碼導出為所需格式。

我可以自定義生成條碼的大小和外觀嗎?

是的,IronBarcode允許您使用ResizeTo()方法自定義條碼尺寸。您還可以應用可選的樣式,使用字體大小和邊距,以確保條碼符合您的具體要求。

該程式庫是否包括條碼格式的自動驗證?

IronBarcode包含所有支持的條碼格式的自動驗證和合規性檢查。這確保生成的條碼符合行業標準,並可被標準條碼讀取器掃描。

為什麼應該使用線性條碼而不是2D條碼?

線性條碼仍然是行業標準,因為它們速度快、可靠,並幾乎可與任何掃描器搭配使用。由於它們不需要複雜的影像處理,IronBarcode的線性條碼在零售結帳線和輸送帶等高速環境中表現出色。

IronBarcode是否提供自定義條碼外觀的支持?

是的,IronBarcode提供了廣泛的條碼外觀自定義選項,包括顏色、大小和文字註釋,讓您可以根據具體設計需求定制條碼。

IronBarcode如何幫助改善業務流程效率?

IronBarcode通過使條碼生成和讀取快速且準確來提高業務流程效率,減少手動資料輸入錯誤,並改善庫存和資產追蹤。

將IronBarcode實現於專案中需要什麼程式設計技能?

基本的C#程式設計知識足以將IronBarcode實現於專案中,因為它提供了簡單的方法和全面的文件來指導開發者。

IronBarcode適合於小型專案和大型企業應用嗎?

IronBarcode設計為可擴展且多功能,使其適合小型專案和需要強大條碼解決方案的大型企業應用。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備好開始了嗎?
Nuget 下載 2,317,217 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在滾動嗎?

想快速驗證嗎? PM > Install-Package BarCode
運行範例觀看您的字串成為條碼。