Barcode with Logos

Contents
[ ]

Create Barcode with Logo Aspose.BarCode for .NET allows developers to generate barcodes with a logo or other images inside it instead of barcode text. The following code sample illustrates how this can be implemented.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_CreateAndManage2DBarCodes();
// Create an instance of BarcodeGenerator class
// Set the barcode text
// Set the barcode symbology
using (BarcodeGenerator generator = new BarcodeGenerator (EncodeTypes.EAN13, "123456789012"))
{
// Generate Barcode image and store it in a Bitmap
using (System.Drawing.Bitmap barcode = generator.GenerateBarCodeImage())
{
// Load the logo/other image as Bitmap
using (System.Drawing.Bitmap picture = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(dataDir + "logo.png"))
{
// Create a new empty image with new Calculated height & width
using (System.Drawing.Bitmap output = new System.Drawing.Bitmap(System.Math.Max(barcode.Width, picture.Width), barcode.Height + picture.Height))
{
// Get the Graphics object9
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(output))
{
// Clear the canvas
g.Clear(System.Drawing.Color.White);
// Draw the primary image (barcode image) on the canvas
g.DrawImage(picture, new System.Drawing.PointF(0, 0));
// Draw the second image (logo image) on the canvas inside the barcode image
g.DrawImage(barcode, new System.Drawing.PointF(0, picture.Height));
}
output.Save(dataDir + "output.jpg");
Console.WriteLine(Environment.NewLine + "Barcode saved at " + dataDir + "output.jpg");
}
}
}
}