VintaSoft Barcode .NET SDK v10.0
Vintasoft.Barcode.GS1 Namespace / GS1Codec Class
Members Example




In This Topic
    GS1Codec Class
    In This Topic
    Class that allows to encode/decode the GS1 information from barcode.
    Object Model
    GS1Codec ClassGS1Codec ClassGS1Codec ClassGS1Codec ClassGS1Codec ClassGS1Codec ClassGS1Codec Class
    Syntax
    'Declaration
     
    Public Class GS1Codec 
    'Usage
     
    Dim instance As GS1Codec
    public class GS1Codec 
    public __gc class GS1Codec 
    public ref class GS1Codec 
    Example
    This example shows how to generate Code128 barcode with GS1 information (GS1-128) and read generated barcode.
    Imports System.Drawing   
    Imports System.Text   
       
    Imports Vintasoft.Barcode   
    Imports Vintasoft.Barcode.BarcodeInfo   
    Imports Vintasoft.Barcode.GS1   
    Imports Vintasoft.Barcode.SymbologySubsets   
       
    ''' <summary>   
    ''' Test that shows how to encode the barcode data in GS1 format using the GS1Codec class,   
    ''' create image with GS1-128 barcode,   
    ''' read GS1-128 barcode from image and   
    ''' parse data stored in GS1 format.   
    ''' </summary>   
    Class GS1CodecExample   
       
    	''' <summary>   
    	''' Runs the test.   
    	''' </summary>   
    	Public Shared Sub TestGS1Codec()   
    		Dim valueVisible As Boolean = True   
       
    		' form the GS1 Application identifiers   
       
    		Dim aiValues As GS1ApplicationIdentifierValue() = New GS1ApplicationIdentifierValue(3) {}   
    		Dim ai As GS1ApplicationIdentifier   
    		' 01 - Global Trade Item Number   
    		ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("01")   
    		aiValues(0) = New GS1ApplicationIdentifierValue(ai, "0123456789123C")   
    		' 310 - Net weight, kilograms   
    		ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("310")   
    		aiValues(1) = New GS1ApplicationIdentifierValue(ai, "0012.55")   
    		' 30 - Count of Items   
    		ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("30")   
    		aiValues(2) = New GS1ApplicationIdentifierValue(ai, "10")   
    		' 90 - Company Internal Information   
    		ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("90")   
    		aiValues(3) = New GS1ApplicationIdentifierValue(ai, "ABCabc12345")   
       
    		' get GS1 printable value   
    		Dim printableValue As New StringBuilder()   
    		For Each value As GS1ApplicationIdentifierValue In aiValues   
    			printableValue.Append(value)   
    		Next   
       
       
    		' create the barcode writer   
    		Dim writer As New BarcodeWriter()   
       
    		' specify that writer must create output image as 24-bpp image   
    		writer.Settings.PixelFormat = BarcodeImagePixelFormat.Bgr24   
       
    		' specify that writer must generate Code128 barcode   
    		writer.Settings.Barcode = BarcodeType.Code128   
       
    		' encode GS1 value in GS1-128 symbology   
    		writer.Settings.Value = GS1Codec.GS1_128.Encode(aiValues, writer.Settings)   
    		' set printable value   
    		If valueVisible Then   
    			writer.Settings.ValueVisible = True   
    			writer.Settings.PrintableValue = printableValue.ToString()   
    		Else   
    			writer.Settings.ValueVisible = False   
    		End If   
       
    		' create image with barcode   
    		Using barcodeImage As Image = writer.GetBarcodeAsBitmap()   
    			' delete aiValues array   
    			aiValues = Nothing   
       
    			' create 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)   
       
    				' read barcode from image   
    				Dim infos As IBarcodeInfo() = reader.ReadBarcodes(barcodeImage)   
       
    				' gets a GS1 Application identifiers from barcode value               
    				aiValues = DirectCast(infos(0), GS1BarcodeInfo).ApplicationIdentifierValues   
       
    				printableValue = New StringBuilder()   
       
    				' print Application identifiers values   
    				For i As Integer = 0 To aiValues.Length - 1   
    					Dim aiValue As GS1ApplicationIdentifierValue = aiValues(i)   
    					ai = aiValue.ApplicationIdentifier   
    					Console.WriteLine(String.Format("[{0}] {1}", i + 1, aiValue))   
    					Console.WriteLine(String.Format("Application identifier   : {0}", 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))   
    					Console.WriteLine()   
    					printableValue.Append(aiValue.ToString())   
    				Next   
       
    				' print GS1 printable value   
    				Console.WriteLine("Printable GS1 value: " & printableValue.ToString())   
    			End Using   
    		End Using   
    	End Sub   
    End Class
    using System;
    using System.Drawing;
    using System.Text;
                
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.BarcodeInfo;
    using Vintasoft.Barcode.GS1;
    using Vintasoft.Barcode.SymbologySubsets;
                
    /// <summary>
    /// Test that shows how to encode the barcode data in GS1 format using the GS1Codec class,
    /// create image with GS1-128 barcode,
    /// read GS1-128 barcode from image and
    /// parse data stored in GS1 format.
    /// </summary>
    class GS1CodecExample
    {
                
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void TestGS1Codec()
        {
            bool valueVisible = true;
                
            // form the GS1 Application identifiers
                
            GS1ApplicationIdentifierValue[] aiValues = new GS1ApplicationIdentifierValue[4];
            GS1ApplicationIdentifier ai;
            // 01 - Global Trade Item Number
            ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("01");
            aiValues[0] = new GS1ApplicationIdentifierValue(ai, "0123456789123C");
            // 310 - Net weight, kilograms
            ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("310");
            aiValues[1] = new GS1ApplicationIdentifierValue(ai, "0012.55");
            // 30 - Count of Items
            ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("30");
            aiValues[2] = new GS1ApplicationIdentifierValue(ai, "10");
            // 90 - Company Internal Information
            ai = GS1ApplicationIdentifiers.FindApplicationIdentifier("90");
            aiValues[3] = new GS1ApplicationIdentifierValue(ai, "ABCabc12345");
                
            // get GS1 printable value
            StringBuilder printableValue = new StringBuilder();
            foreach (GS1ApplicationIdentifierValue value in aiValues)
                printableValue.Append(value);
                
                
            // create the barcode writer
            BarcodeWriter writer = new BarcodeWriter();
                
            // specify that writer must create output image as 24-bpp image
            writer.Settings.PixelFormat = BarcodeImagePixelFormat.Bgr24;
                
            // specify that writer must generate Code128 barcode
            writer.Settings.Barcode = BarcodeType.Code128;
                
            // encode GS1 value in GS1-128 symbology
            writer.Settings.Value = GS1Codec.GS1_128.Encode(aiValues, writer.Settings);
            // set printable value
            if (valueVisible)
            {
                writer.Settings.ValueVisible = true;
                writer.Settings.PrintableValue = printableValue.ToString();
            }
            else
            {
                writer.Settings.ValueVisible = false;
            }
                
            // create image with barcode
            using (Image barcodeImage = writer.GetBarcodeAsBitmap())
            {
                // delete aiValues array
                aiValues = null;
                
                // create 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);
                    
                    // read barcode from image
                    IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeImage);
                
                    // gets a GS1 Application identifiers from barcode value            
                    aiValues = ((GS1BarcodeInfo)infos[0]).ApplicationIdentifierValues;
                
                    printableValue = new StringBuilder();
                
                    // print Application identifiers values
                    for (int i = 0; i < aiValues.Length; i++)
                    {
                        GS1ApplicationIdentifierValue aiValue = aiValues[i];
                        ai = aiValue.ApplicationIdentifier;
                        Console.WriteLine(string.Format("[{0}] {1}", i + 1, aiValue));
                        Console.WriteLine(string.Format("Application identifier   : {0}", 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));
                        Console.WriteLine();
                        printableValue.Append(aiValue.ToString());
                    }
                
                    // print GS1 printable value
                    Console.WriteLine("Printable GS1 value: " + printableValue.ToString());
                }
            }
        }
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Barcode.GS1.GS1Codec

    Requirements

    Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also