GS1-128

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

Czy IronBarcode obsługuje symbole GS1 UCC/EAN-128?

BarCodes w formacie GS1 są rozpoznawane i dekodowane z dużą dokładnością. Problem polega jednak na obecnym braku nawiasów w wyświetlanej wartości BarCode.

Podczas korzystania z GS1-128, IronBarcode obecnie generuje: 01950123456789033103000123 (co jest rozpoznawane jako kod kreskowy Code 128 z sygnaturą GS1). Pożądana wartość do wyświetlenia na obrazie to: 01950123456789033103000123. Jednak skaner kodów kreskowych wygeneruje (01)95012345678903(3103)000123, wykrywając typ kodu kreskowego jako Code128.

Aby wygenerować BARCODE GS1-128, użyj następującego kodu:

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");
    }
}
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");
    }
}
Imports IronBarCode

Friend Class BarcodeExample
	Shared Sub Main()
		' Create a GS1-128 barcode using the specified value
		Dim barcode As GeneratedBarcode = 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")
	End Sub
End Class
$vbLabelText   $csharpLabel

BarCode wyjściowy

Przykład generowania kodu kreskowego

Powyższy kod generuje BARCODE GS1-128 z domyślnym separatorem. Jeśli chcesz dodać dodatkowe znaczniki, możesz wstawić separator Unicode \u00f1. Należy jednak zauważyć, że przy użyciu metody AddBarcodeValueTextBelowBarcode, wyświetlony zostanie znak Unicode ñ (kod 0x00F1). Aby obejść to ograniczenie, alternatywnym podejściem jest manipulacja ciągiem znaków i przekazanie zmodyfikowanej wartości do metody AddAnnotationTextBelowBarcode. W ten sposób można uzyskać pożądane wyświetlenie wartości kodu kreskowego bez znaku ñ.

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");
    }
}
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");
    }
}
Imports IronBarCode

Friend Class BarcodeExampleWithAnnotation
	Shared Sub Main()
		' Original barcode value
		Dim barcodeValue As String = "0195012345678903310300012300" & ChrW(&H00f1).ToString() & "0000000123300000" & ChrW(&H00f1).ToString() & "0000012312300000"

		' Remove unwanted unicode characters for display purposes
		Dim trimmedString As String = barcodeValue.Replace(ChrW(&H00f1).ToString(), "")

		' Create a GS1-128 barcode using the original value
		Dim barcode As GeneratedBarcode = 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")
	End Sub
End Class
$vbLabelText   $csharpLabel

BarCode wyjściowy

Wyjście kodu kreskowego z adnotacją przykład

Podczas skanowania kodu kreskowego, wyjście będzie (01)95012345678903(3103)000123(00)0000000123300000(00)00012312300000, a typ kodu kreskowego zostanie wykryty jako GS1Code128.

Analiza kodowania GS1-128

IronBarcode może również analizować fizyczne kodowanie kodu kreskowego GS1-128, pokazując, które zestawy znaków Code 128 (A, B lub C) są używane dla każdego segmentu danych. Użyj metody Code128GS1Parser.ParseWithEncoding, aby rozparsować ciąg GS1 z dołączoną analizą kodowania.

using IronBarCode;

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

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

' GS1-128 with encoding analysis
Dim gs1Result = Code128GS1Parser.ParseWithEncoding("(01)09501101530003")
Console.WriteLine(gs1Result.CharacterSetSummary)  ' "C"
Console.WriteLine(gs1Result.HasEncodingInfo)      ' True
$vbLabelText   $csharpLabel

Ponieważ dane GS1-128 są głównie numeryczne, enkoder używa Code C dla maksymalnej kompaktowości. Właściwość HasEncodingInfo potwierdza, że analiza kodowania jest dostępna na wyniku.

Curtis Chau
Autor tekstów technicznych

Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podrę...

Czytaj więcej
Gotowy, aby rozpocząć?
Nuget Pliki do pobrania 2,145,441 | Wersja: 2026.4 just released
Still Scrolling Icon

Wciąż przewijasz?

Czy chcesz szybko dowodu? PM > Install-Package BarCode
uruchom przykład zobacz, jak twoje ciągi zamieniają się w kody kreskowe.