如何建立一維BarCode與線性BarCode

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

IronBarcode 讓您能夠透過簡單的 C# 程式碼,生成所有主要的一維 BarCode 格式,包括 Code 128、GS1-128、Code 39、Code 93、EAN-13、EAN-8、UPC-A、UPC-E、Intelligent Mail、MSI、Codabar 及 DataBar,並具備自動驗證與合規性檢查功能。 您可以瀏覽支援的BarCode格式完整清單,以找到符合您需求的BarCode格式。

線性BarCode仍是傳遞資訊的業界標準。 它們速度快、可靠,且幾乎能與任何掃描器配合使用。 由於這些BARCODE無需複雜的影像處理,因此在零售結帳櫃檯和輸送帶等高速環境中表現尤為出色。

主要挑戰在於根據您的具體需求選擇正確的格式。 您可能需要 Code128 的高資料密度來製作運送標籤、EAN8 的緊湊尺寸來標示小型產品,或是 IntelligentMail BarCode 的嚴格格式來符合郵政服務規範。 IronBarcode 可協助您高效且可靠地生成所有這些格式。 此函式庫亦支援多種輸出資料格式,可與您的現有系統無縫整合。

本指南涵蓋如何使用 IronBarcode 生成最重要的 1D 條碼格式,以及其常見的應用情境。


快速入門:建立您的第一個一維BarCode using IronBarcode 的簡易 API,從字串建立 Code128 BarCode,並將其儲存為 JPEG 影像。 立即開始——提供資料、選擇編碼與尺寸,並寫入您的圖像檔案。

  1. using NuGet 套件管理員安裝 https://www.nuget.org/packages/BarCode

    PM > Install-Package BarCode
  2. 請複製並執行此程式碼片段。

    IronBarCode.BarcodeWriter.CreateBarcode("HELLO-WORLD-123", BarcodeEncoding.Co/de128, 250, 100).SaveAsJpeg("MyFirstBarcode.jpg");
  3. 部署至您的生產環境進行測試

    立即透過免費試用,在您的專案中開始使用 IronBarcode

    arrow pointer

如何建立一維BarCode和線性BarCode?

線性一維BarCode利用寬度可變的線條與空格,以水平方式儲存資料。 二維 BarCode(如 QR 碼)利用方格網格在二維空間中儲存資訊。 雖然二維條碼能容納更多資料(例如網址或聯絡名片),但一維BARCODE僅限於短的字母數字字串。

這種簡潔性使一維BarCode能夠更快地被掃描。 這使它們能與標準雷射掃描器廣泛相容,非常適合用於高速零售及物流環境。 若需處理大量掃描應用程式,請探索我們的讀取速度選項以優化效能。

讓我們來了解最受支援的格式,以及如何使用 IronBarcode 來建立這些格式。

如何建立 Code-128 BARCODE?

Code 128 BARCODE常被用於內部物流及運送標籤。 它支援完整的 128 個 ASCII 字元範圍,因此能將標準數字和英文文字高效壓縮至有限空間內。 這使得 Code 128 成為倉庫管理系統與庫存追蹤的理想選擇,在這些場景中,空間雖受限,但資料密度卻至關重要。

然而,若未安裝額外擴充套件,它並未原生支援 Unicode 或非拉丁字元。 該工具無法處理中文或阿拉伯文等語言中的複雜字元,且會誤判資料,導致輸出結果不正確。 若您的應用程式需要 Unicode 支援,請參閱我們關於編寫 Unicode BarCode 的指南。

我需要什麼程式碼?

IronBarcode 讓生成 Code-128 條碼變得簡單:在呼叫 Create 方法時,將 BarcodeEncoding.Co/de128 作為第二個參數傳入,然後匯出為圖片。 進一步了解如何使用各種格式和選項來建立BarCode圖像

: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 BARCODE?

GS1-128 是一種建基於 Code 128 之上的附加資料格式。GS1-128 的主要優勢在於能實現全球一致的資料解讀,從而消除誤解與歧義。 此標準化對供應鏈管理至關重要,因為產品會在不同公司與國家之間流通。

然而,由於格式規範嚴格,若遺漏隱藏控制字元或欄位長度不正確,將導致BarCode不符合規範。 若您在 GS1-128 格式設定方面遇到問題,我們的 GS1-128 疑難排解指南可協助解決常見問題。

GSI-128 要求採用何種格式?

BarCode掃描器使用應用程式識別碼 (AI) ‒ 這是用於識別產品代碼中資訊的數字前綴。 理解這些識別碼對於建立符合規範且能在全球供應鏈中運作的BARCODE至關重要。

GS1-128 遵循以下四部分的資料結構:

(數字前綴 01) GTIN (全球商品編號):用於識別產品類別的唯一產品識別碼。 必須精確為 14 位數位。 若產品代碼較短,請在開頭補上零。 例如,123456789012 應轉換為 00123456789012。

(數字前綴 10) 批次/批號:產品的批次或批號。 1 至 20 個英數字元。 若置於 BarCode 中間,需加入 FNC1 分隔字元,以便掃描器辨識 BarCode 結束位置。 若位於BarCode末端,則無需分隔符。

(數字前綴 17) 到期日期:產品的到期日期。 固定為六位數,採用 YYMMDD 格式。 例如,251231 代表 2025 年 12 月 31 日。採用兩位數年份,並以滑動視窗方式表示世紀。

(數字前綴 21) 序號:識別該產品單一實體的唯一序號。 變長字串,包含 1 至 20 個英數字元。

請注意僅需提供 GTIN; (batch、expiry 和 serial 屬性為選用。)}]

警告雖然僅需提供 GTIN,但部分零售商有其特定的合規準則。 (製作BARCODE時請確認其規格。)}]

如何使用 IronBarcode 生成 GSI-128?

生成 GS1-128 BARCODE 非常簡單; 在呼叫 Create 時,將 BarcodeEncoding.Co/de128GS1 作為第二個參數傳入。

以下範例展示了一個符合 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 BARCODE?

Code 39 是最早的字母數字 BARCODE 標準之一,以可靠性著稱。 常見於汽車及國防產業。 其無需校驗位元即可編碼字母與數字的能力,使其適用於透過其他方式驗證資料完整性的環境。

然而,Code 39 的字元集有所限制。 僅允許使用大寫英文字母、數字及符號(如 /、.、- 等)。標準模式不支援小寫字母。 有關讀取標準及擴展版 Code 39 BARCODE 的資訊,請參閱我們的 Code 39 讀取指南

Code 39 需要什麼代碼?

若要產生 Code39 條碼,請在使用 Create 時,將 BarcodeEncoding.Co/de39 作為第二個參數傳入。

以下為範例:

: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 BARCODE; 僅支援讀取功能。 如需了解擴展型與標準型 Code 39 的讀取方式,請參閱我們的 Code 39 讀取教學指南
。)}]

如何建立 Code 93 BARCODE?

Code 93 改進了 Code 39,後者常應用於物流及電子元件標籤領域,這些場合通常空間有限,但又需要儲存字母數字資料。 改良後的密度更適合空間有限的小型電子元件。

支援所有 ASCII 字元、大寫英文字母、數字及符號。 提供比 Code 39 更高的編碼密度。

Code 93 需要什麼程式碼?

若要產生 Code93,請在使用 Create 時,將 BarcodeEncoding.Co/de93 作為第二個參數傳入:

: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 BarCode?

Codabar 對列印品質不佳的情況具有強大的抗干擾能力,廣泛應用於血庫和圖書館。 此格式具備理想的容錯能力,特別適合用於品質較差的印表機或因長期使用而磨損的設備。

字元長度可變,但字元集有限。 僅包含數位(0-9)及符號 (-, $, :, /, ., +)。 起始/結束字元 A、B、C、D 表示段落的起始或結束。 這些字元不能出現在BarCode的中間位置。

使用 CodaBar 需要哪些程式碼?

若要產生 Codabar 條碼,請在使用 Create 時,將 BarcodeEncoding.Co/dabar 作為第二個參數傳入:

: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 BarCode?

GS1 DataBar(前身為 RSS-14)體積更為緊湊,專為產品識別碼而設計。 適用於新鮮農產品等體積較小的商品,因傳統BarCode佔用空間過大。 請參閱我們的"新格式里程碑更新",進一步了解最新格式功能。

如同 GS1-128,其編碼格式具有嚴格規範。 "Omnidirectional"變體包含產品代碼屬性。

GS1-DataBar 需要什麼格式?

(數字前綴-01) GTIN (全球商品編號):產品專屬的識別碼。 必須精確為 14 位數位。

警告標準"GS1 DataBar Omnidirectional"能容納 GTIN (01)。 (若需額外屬性,請使用 GS1 DataBar Expanded。)}]

如何生成 GS1 DataBar 條碼?

若要產生 GS1 DataBar,請在使用 Create 時,將 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 BARCODE?

EAN-13 是全球消費性產品通用的標準零售 BarCode,亦是最廣泛使用的格式之一。 針對零售應用,請探索如何自訂BarCode樣式以符合品牌需求。

EAN-13 需遵守嚴格的授權規範。 若未取得 GS1 公司前綴授權以確保 BARCODE 唯一性,則不得生成供公眾使用的 EAN-13 編號。 僅包含 13 位數位。 如需授權資訊,請造訪我們的授權頁面

EAN-13 具有特定的格式規範。

EAN-13 需要什麼格式?

EAN-13 BARCODE 由四個部分組成:

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

製造商代碼:由 GS1 指派的可變長度代碼。

產品代碼:由製造商指派給特定商品的代碼。

校驗位(末一位):採用模 10 演算法,根據前 12 位數計算得出。 確保掃描讀取的準確性。

警告前綴 200-299 保留供受限流通使用。 (在生成 EAN-13 BARCODE 時,請勿在生產環境中使用這些前綴。)}]

如何生成 EAN-13 條碼?

若要產生 EAN-13 條碼,請在使用 Create 時,將 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 BARCODE?

EAN-8 是 EAN-13 的精簡版本,適用於全尺寸 BARCODE 佔用空間過大的小型消費性產品。 常見於鉛筆和化妝品等包裝空間有限的產品上。

與 Code 128 或 Code 39 不同,EAN-8 使用特定的指定前綴,而非隨機數字。

EAN-8 採用嚴格的 8 位數格式:7 位數據位數和 1 位校驗位數。 僅限數字。

我需要哪些程式碼來處理 EAN-8?

若要建立 EAN-8,在使用 Create 時,需將 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 例外情況

如何建立智能郵件BarCode?

智能郵件 BARCODE (IMB) 是美國郵政總局 (USPS) 用於自動化郵件分揀與追蹤的標準。 與傳統的寬度調變 BarCode 不同,IMB 採用高度調變 BarCode。 適用於信件及平信的自動化價格折扣。 僅支援特定長度的數字:20、25、29 或 31 位數。

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

Intelligent Mail 需要什麼格式?

(前 2 位數位) BarCode ID:BarCode 識別碼。 嚴格限制為 2 位數數位。 一般標準商業郵件通常為 00。

(後 3 位數位) 服務類型識別碼 (STID):定義郵件類別(例如:一等郵件、行銷郵件)及服務項目(例如:地址更正、追蹤)。 對郵資折扣至關重要。

(後 6 或 9 位數字) 郵寄識別碼 (MID):由美國郵政總局 (USPS) 指派給貴公司的 6 位或 9 位數字。

(後 6 或 9 位數位) 序號:用於識別單一郵件的唯一標識碼。

(最後 0、5、9 或 11 位數位) 路由代碼:配送 ZIP 區號。

如何生成智能郵件代碼?

若要產生 IMB,請在呼叫 Create 時,將 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 BarCode?

MSI 常見於零售貨架標籤和倉庫庫存管理,鮮少出現在消費性產品上。 其簡易性與可靠性使其在內部運作中廣受歡迎。 若遇到 MSI 識別問題,請參閱我們的 MSI BarCode 疑難排解指南

MSI 僅為數字; 不允許包含任何字母或符號。 變長字串,通常為 10 至 15 位元組。

MSI 需要哪些程式碼?

若要產生 MSI,請在呼叫 Create 時,將 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 BARCODE?

UPC-A 是美國與加拿大通用的標準零售 BARCODE。 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,請在呼叫 Create 時,將 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 BARCODE?

UPC-E 是 UPC-A 的精簡版本,適用於汽水罐等小型零售包裝,因完整 12 位數的 UPC-A 過於佔用空間。 該壓縮演算法能將相同資訊以約一半的空間進行編碼。

如同 UPC-A,僅限數字。 不接受任何字母或符號。

UPC-E 需要哪些程式碼?

要產生 UPC-E,請在呼叫 Create 時,將 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 BARCODE 類型?

名稱 格式 常見用法 限制與注意事項
Code 128 支援全 ASCII 128 位元組的英數字
。可變長度。高密度。
內部物流、運送標籤、資產追蹤、身分證。
  • 不支援 Unicode:若要維持掃描器相容性,無法原生編碼特殊字元(如中文或表情符號)。
  • 印表機品質:需具備高解析度;低 DPI 的熱感應式列印可能會導致可讀性問題。
GS1-128 帶前綴的結構化字母
數字代碼 128 FNC1 + 應用程式識別碼(例如, (01)).
全球供應鏈(沃爾瑪/亞馬遜)、托盤標籤、EDI。
  • 缺少 FNC1:必須以隱藏字元 FNC1 字元,否則掃描器會將其視為原始文字。
  • 括號說明請勿對 () ;這些僅供人類閱讀之用。
Code 39 字母數字(受限)
大寫 A-Z、0-9 以及 -. $ / + % space.
汽車產業 (AIAG)、國防產業 (LOGMARS)、傳統工業識別碼。
  • 不支援小寫:若輸入"a",標準模式將失敗。擴展模式雖支援此功能,但需特定掃描器設定。
  • 低密度:會產生非常寬的BarCode,不適用於小型標籤。
Code 93 字母
數字型號,與 Code 39 類似,但具有更高的密度。
電子產品(PCB)、加拿大郵政,以及內部製造。
  • 校驗位數:需包含兩個強制性的校驗位數(C 和 K)。請勿手動計算,應交由函式庫處理。
  • 掃描器支援:通常預設在掃描器上停用,以避免與 Code 39 產生衝突。
Codabar 數字 + 符號
0-9 以及 - $ : /. +。起始/結束:A、B、C、D。
血庫、圖書館、FedEx 空運運單(舊版)。
  • 短句:容易發生掃描器僅讀取部分程式碼的錯誤(例如,將"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 位)
高度調變(4 態)條碼。
USPS 郵件分揀與自動化。
  • 嚴格長度限制:輸入內容必須與 USPS 欄位(BarCode ID、STID、MID、序號、ZIP)完全一致。
  • STID "234":請勿在實際運作環境中使用此範例 ID;否則可能導致郵件被拒收或優惠失效。
MSI (Plessey) 僅限
數字,變長格式。
零售貨架標籤、倉庫貨箱。
  • 校驗碼混淆:支援 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、智能郵件條碼、MSI、Codabar和DataBar。每種格式適合不同的應用 - Code 128用於運單標籤,EAN-8用於小型產品,智能郵件條碼用於郵政服務。

如何在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 University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備好開始了嗎?
Nuget 下載 2,240,258 | 版本: 2026.5 just released
Still Scrolling Icon

還在捲動嗎?

想要快速證明? PM > Install-Package BarCode
執行範例 看您的字串變成 BarCode。