C# Code for Generating Multiple Barcodes on a Single Image - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# Code for Generating Multiple Barcodes on a Single Image

sheraz786sheraz786 Posts: 20Member
in C#

This Technical tip explains how .NET developers can generate multiple barcodes on a single image inside their applications using Aspose.BarCode for .NET. Aspose.BarCode for .NET can efficiently create multiple optimized barcodes on a single image. It also supports generating multiple type of barcodes such as postal, QR, PDF417, EAN, Code 39, Code128, ISBN, MSI, GS1 etc.

The following code snippet shows how to generate multiple barcodes on a single image

[C# Code Sample]

Dictionary<string, Symbology> collection = new Dictionary<string, Symbology>(); collection.Add("ONE123", Symbology.Code39Standard); collection.Add("Process Collection", Symbology.DataMatrix); collection.Add("Dictionary Collection", Symbology.QR); collection.Add("X06712AT", Symbology.Code128); collection.Add("979026000043", Symbology.EAN13); collection.Add("Aztec BarCode", Symbology.Aztec);

List images = new List();

foreach (KeyValuePair<string, Symbology> pair in collection) using (BarCodeBuilder builder = new BarCodeBuilder()) { builder.CodeText = pair.Key; builder.SymbologyType = pair.Value; images.Add(builder.GenerateBarCodeImage()); }

int maxWidth = int.MinValue; int sumHeight = 0; foreach (Bitmap bmp in images) { sumHeight += bmp.Height; if (maxWidth < bmp.Width) maxWidth = bmp.Width; }

const int offset = 10; Bitmap resultBitmap = new Bitmap(maxWidth + offset * 2, sumHeight + offset * images.Count); using (Graphics g = Graphics.FromImage(resultBitmap)) { g.Clear(Color.White);

int yPosition = offset;
for (int i = 0; i < images.Count; ++i)
    Bitmap currentBitmap = images[i];
    g.DrawImage(currentBitmap, offset, yPosition);
    yPosition += currentBitmap.Height + offset;


resultBitmap.Save("barcode.png", ImageFormat.Png);

For VB.NET code sample and other details please visit here:

Sign In or Register to comment.