How to Generate Multiple Barcodes on a Single Image inside .NET Apps
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. Aspose.BarCode is a .NET component for generation and recognition of Linear and 2D barcodes on all kinds of .NET applications. Also take image output in BMP, GIF, JPEG, PNG and WMF formats. You can also control image styles such as background color, bar color etc.
//your code here...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<Bitmap> images = new List<Bitmap>();
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);
[VB.NET Code Sample]
Dim collection As New Dictionary(Of 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)
Dim images As New List(Of Bitmap)()
For Each pair As KeyValuePair(Of String, Symbology) In collection
Using builder As New BarCodeBuilder()
builder.CodeText = pair.Key
builder.SymbologyType = pair.Value
images.Add(builder.GenerateBarCodeImage())
End Using
Next
Dim maxWidth As Integer = Integer.MinValue
Dim sumHeight As Integer = 0
For Each bmp As Bitmap In images
sumHeight += bmp.Height
If maxWidth < bmp.Width Then
maxWidth = bmp.Width
End If
Next
Const offset As Integer = 10
Dim resultBitmap As New Bitmap(maxWidth + offset * 2, sumHeight + offset * images.Count)
Using g As Graphics = Graphics.FromImage(resultBitmap)
g.Clear(Color.White)
Dim yPosition As Integer = offset
For i As Integer = 0 To images.Count - 1
Dim currentBitmap As Bitmap = images(i)
g.DrawImage(currentBitmap, offset, yPosition)
yPosition += currentBitmap.Height + offset
Next
End Using
resultBitmap.Save("barcode.png", ImageFormat.Png)
Url: http://www.aspose.com/docs/display/barcodenet/Generate+Multiple+Barcodes+on+a+Single+Image
Language: C# | User: Sheraz Khan | Created: Jul 23, 2014 | Tags: generate multiple barcodes on single image generating multiple type of barcodes create multiple barcodes using .NET Barcode image Recognition in .NET recognizing the barcode .NET Barcode API