VintaSoft Barcode .NET SDK 14.3: Documentation for .NET developer
In This Topic
    How to read GS1-128 barcode?
    In This Topic
    Example: Here is an example that shows how to detect GS1-128 barcode in an image file and parse barcode data stored in GS1 format.
    /// <summary>
    /// Recognizes GS1-128 barcodes in specified image.
    /// </summary>
    /// <param name="filename">The filename of image file with barcodes.</param>
    public static void Recognize(string filename)
    {
        // create the barcode reader
        using (BarcodeReader reader = new BarcodeReader())
        {
            // specify that reader must search for GS1-128 barcodes only
    
            reader.Settings.ScanBarcodeTypes = BarcodeType.None;
            reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.GS1_128);
    
            // recognize barcodes in image
            IBarcodeInfo[] infos = reader.ReadBarcodes(filename);
    
            // for each found barcode
            for (int j = 0; j < infos.Length; j++)
            {
                GS1BarcodeInfo info = (GS1BarcodeInfo)infos[j];
    
                // print barcode symbology
                Console.WriteLine(info.BarcodeSubset);
    
                // print barcode region on image
                Console.WriteLine(info.Region.ToString());
    
                // print Transmitted data
                Console.WriteLine(string.Format("Transmitted data            : {0} ", info.TransmittedData));
    
                // print values of Application identifiers
                StringBuilder printableValue = new StringBuilder();
                GS1ApplicationIdentifierValue[] aiValues = info.ApplicationIdentifierValues;
                for (int i = 0; i < aiValues.Length; i++)
                {
                    GS1ApplicationIdentifierValue aiValue = aiValues[i];
                    GS1ApplicationIdentifier ai = aiValue.ApplicationIdentifier;
                    Console.WriteLine(string.Format("Application identifier {0}    : {1}", i + 1, ai.ApplicationIdentifier));
                    Console.WriteLine(string.Format("  Value                     : {0}", aiValue.Value));
                    Console.WriteLine(string.Format("  Data title                : {0}", ai.DataTitle));
                    Console.WriteLine(string.Format("  Data content              : {0}", ai.DataContent));
                    Console.WriteLine(string.Format("  Format                    : {0}", ai.Format));
                    Console.WriteLine(string.Format("  Is contains decimal point : {0}", ai.IsContainsDecimalPoint));
                    Console.WriteLine(string.Format("  Is variable length        : {0}", ai.IsVariableLength));
                    printableValue.Append(aiValue.ToString());
                }
    
                // print GS1 printable value
                Console.WriteLine("Printable GS1 value: " + printableValue.ToString());
                Console.WriteLine();
            }
        }
    }
    
    ''' <summary>
    ''' Recognizes GS1-128 barcodes in specified image.
    ''' </summary>
    ''' <param name="filename">The filename of image file with barcodes.</param>
    Public Shared Sub Recognize(filename As String)
        ' create the barcode reader
        Using reader As New BarcodeReader()
            ' specify that reader must search for GS1-128 barcodes only
    
            reader.Settings.ScanBarcodeTypes = BarcodeType.None
            reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.GS1_128)
    
            ' recognize barcodes in image
            Dim infos As IBarcodeInfo() = reader.ReadBarcodes(filename)
    
            ' for each found barcode
            For j As Integer = 0 To infos.Length - 1
                Dim info As GS1BarcodeInfo = DirectCast(infos(j), GS1BarcodeInfo)
    
                ' print barcode symbology
                Console.WriteLine(info.BarcodeSubset)
    
                ' print barcode region on image
                Console.WriteLine(info.Region.ToString())
    
                ' print Transmitted data
                Console.WriteLine(String.Format("Transmitted data            : {0} ", info.TransmittedData))
    
                ' print values of Application identifiers
                Dim printableValue As New StringBuilder()
                Dim aiValues As GS1ApplicationIdentifierValue() = info.ApplicationIdentifierValues
                For i As Integer = 0 To aiValues.Length - 1
                    Dim aiValue As GS1ApplicationIdentifierValue = aiValues(i)
                    Dim ai As GS1ApplicationIdentifier = aiValue.ApplicationIdentifier
                    Console.WriteLine(String.Format("Application identifier {0}    : {1}", i + 1, ai.ApplicationIdentifier))
                    Console.WriteLine(String.Format("  Value                     : {0}", aiValue.Value))
                    Console.WriteLine(String.Format("  Data title                : {0}", ai.DataTitle))
                    Console.WriteLine(String.Format("  Data content              : {0}", ai.DataContent))
                    Console.WriteLine(String.Format("  Format                    : {0}", ai.Format))
                    Console.WriteLine(String.Format("  Is contains decimal point : {0}", ai.IsContainsDecimalPoint))
                    Console.WriteLine(String.Format("  Is variable length        : {0}", ai.IsVariableLength))
                    printableValue.Append(aiValue.ToString())
                Next
    
                ' print GS1 printable value
                Console.WriteLine("Printable GS1 value: " & printableValue.ToString())
                Console.WriteLine()
            Next
        End Using
    End Sub