VintaSoft Barcode .NET SDK 16.0: Documentation for .NET developer
In This Topic
    How to generate GS1 barcode image?
    In This Topic
    Here is C# example that demonstrates how to generate GS-128 barcode image:
    namespace ConsoleApp1
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                // specify that GDI+ must be used as drawing engine
                Vintasoft.Barcode.GdiAssembly.Init();
    
                // an array of Application Identifiers, which should be used in GS-128 barcode
                Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue[] aiValues = 
                    new Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue[2];
                
                // create first Application Identifier
                Vintasoft.Barcode.GS1.GS1ApplicationIdentifier ai =
                    Vintasoft.Barcode.GS1.GS1ApplicationIdentifiers.FindApplicationIdentifier("02");
                aiValues[0] = new Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue(ai, "40529176710608");
    
                // create second Application Identifier
                ai = Vintasoft.Barcode.GS1.GS1ApplicationIdentifiers.FindApplicationIdentifier("400");
                aiValues[1] = new Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue(ai, "WICAV240308BCN1");
    
                // create printable value of GS-128 barcode
                System.Text.StringBuilder printableValue = new System.Text.StringBuilder();
                foreach (Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue value in aiValues)
                {
                    printableValue.Append(value);
                }
    
                // create barcode writer
                using (Vintasoft.Barcode.BarcodeWriter writer = new Vintasoft.Barcode.BarcodeWriter())
                {
                    // specify that barcode writer must create 24-bpp barcode image
                    writer.Settings.PixelFormat = Vintasoft.Barcode.BarcodeImagePixelFormat.Bgr24;
    
                    // specify that barcode writer must generate GS-128 barcode
                    writer.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Code128;
                    writer.Settings.Value = Vintasoft.Barcode.GS1.GS1Codec.GS1_128.Encode(aiValues, writer.Settings);
                    
                    // specify that barcode writer must add barcode text under barcode image
                    writer.Settings.ValueVisible = true;
                    writer.Settings.UseLegacyVectorGenerator = false;
                    writer.Settings.PrintableValue = printableValue.ToString();
                    
                    // generate image (with specified size) of GS-128 barcode
                    Vintasoft.Imaging.VintasoftBitmap barcodeImage =
                        writer.GetBarcodeAsVintasoftBitmap(491, 80, Vintasoft.Barcode.UnitOfMeasure.Pixels);
    
                    // save generated image to a file
                    Vintasoft.Barcode.ImageCodecs.Default.Encode(barcodeImage, "GS128BarcodeImage.png");
                }
            }
        }
    }
    
    Module Module1
    
        Sub Main()
            ' specify that GDI+ must be used as drawing engine
            Vintasoft.Barcode.GdiAssembly.Init()
    
            ' an array of Application Identifiers, which should be used in GS-128 barcode
            Dim aiValues As Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue() = _
                New Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue(1) {}
    
            ' create first Application Identifier
            Dim ai As Vintasoft.Barcode.GS1.GS1ApplicationIdentifier = _
                Vintasoft.Barcode.GS1.GS1ApplicationIdentifiers.FindApplicationIdentifier("02")
            aiValues(0) = New Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue(ai, "40529176710608")
    
            ' create second Application Identifier
            ai = Vintasoft.Barcode.GS1.GS1ApplicationIdentifiers.FindApplicationIdentifier("400")
            aiValues(1) = New Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue(ai, "WICAV240308BCN1")
    
            ' create printable value of GS-128 barcode
            Dim printableValue As New System.Text.StringBuilder()
            For Each value As Vintasoft.Barcode.GS1.GS1ApplicationIdentifierValue In aiValues
                printableValue.Append(value)
            Next
    
            ' create barcode writer
            Using writer As New Vintasoft.Barcode.BarcodeWriter()
                ' specify that barcode writer must create 24-bpp barcode image
                writer.Settings.PixelFormat = Vintasoft.Barcode.BarcodeImagePixelFormat.Bgr24
    
                ' specify that barcode writer must generate GS-128 barcode
                writer.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Code128
                writer.Settings.Value = Vintasoft.Barcode.GS1.GS1Codec.GS1_128.Encode(aiValues, writer.Settings)
    
                ' specify that barcode writer must add barcode text under barcode image
                writer.Settings.ValueVisible = True
                writer.Settings.UseLegacyVectorGenerator = False
                writer.Settings.PrintableValue = printableValue.ToString()
    
                ' generate image (with specified size) of GS-128 barcode
                Dim barcodeImage As Vintasoft.Imaging.VintasoftBitmap = _
                    writer.GetBarcodeAsVintasoftBitmap(491, 80, Vintasoft.Barcode.UnitOfMeasure.Pixels)
    
                ' save generated image to a file
                Vintasoft.Barcode.ImageCodecs.[Default].Encode(barcodeImage, "GS128BarcodeImage.png")
            End Using
        End Sub
    
    End Module