GS1-128

Curtis Chau
Curtis Chau
已更新: 2026年4月22日

IronBarcode 是否支援 GS1 UCC/EAN-128 條碼系統?

採用 GS1 標準的條碼能夠被準確地辨識和解碼。 然而,問題在於目前顯示的條碼值缺少括號。

當使用GS1-128時,IronBarcode當前輸出:01950123456789033103000123(被識別為具有GS1簽名的Code 128條碼)。 希望在圖像輸出上顯示的值為:01950123456789033103000123。 然而,條碼掃描器將輸出(01)95012345678903(3103)000123,並檢測出條碼類型為Code128。

若要產生 GS1-128 條碼,請使用下列程式碼:

using IronBarCode;

class BarcodeExample
{
    static void Main()
    {
        // Create a GS1-128 barcode using the specified value
        GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("01950123456789033103000123", BarcodeWriterEncoding.Code128GS1);

        // Add the barcode value text below the barcode on the generated image
        barcode.AddBarcodeValueTextBelowBarcode();

        // Save the barcode image as a PNG file
        barcode.SaveAsPng("gs1code128.png");
    }
}

輸出條碼

輸出條碼範例

上述程式碼產生帶有預設分隔符號的 GS1-128 條碼。 如果您想添加額外的分隔符,可以插入Unicode分隔符\u00f1。 但是,請注意,當使用AddBarcodeValueTextBelowBarcode方法時,將顯示Unicode字符ñ(代碼0x00F1)。 要克服此限制,需要採用替代方法來操作字串,並將修改後的值傳遞給AddAnnotationTextBelowBarcode方法。 這樣,您就可以在不顯示 ñ 字元的情況下實現所需的條碼值顯示。

using IronBarCode;

class BarcodeExampleWithAnnotation
{
    static void Main()
    {
        // Original barcode value
        string barcodeValue = "0195012345678903310300012300\u00f10000000123300000\u00f10000012312300000";
        
        // Remove unwanted unicode characters for display purposes
        string trimmedString = barcodeValue.Replace("\u00f1", "");

        // Create a GS1-128 barcode using the original value
        GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(barcodeValue, BarcodeWriterEncoding.Code128GS1);

        // Add a custom annotation text below the barcode with the trimmed value
        barcode.AddAnnotationTextBelowBarcode(trimmedString);

        // Save the barcode image as a PNG file
        barcode.SaveAsPng("gs1code128.png");
    }
}

輸出條碼

帶註解的輸出條碼範例

當掃描條碼時,輸出將為(01)95012345678903(3103)000123(00)0000000123300000(00)00012312300000,條碼類型將被檢測為GS1Code128。

分析 GS1-128 編碼

IronBarcode 還能分析 GS1-128 條碼的物理編碼,顯示資料的每個區段使用了哪種 Code 128 字元集(A、B 或 C)。 使用Code128GS1Parser.ParseWithEncoding方法解析包含編碼分析的GS1字串。

using IronBarCode;

// GS1-128 with encoding analysis
var gs1Result = Code128GS1Parser.ParseWithEncoding("(01)09501101530003");
Console.WriteLine(gs1Result.CharacterSetSummary);  // "C"
Console.WriteLine(gs1Result.HasEncodingInfo);      // true

由於 GS1-128 資料主要為數值型,編碼器採用 Code C 以達到最大緊湊度。 HasEncodingInfo屬性確認結果上可用編碼分析。

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

閱讀更多

準備好開始了嗎?

NuGet 下載次數 2,575,633版本:2026.11剛剛發布