Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 6, 2022 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/691bd86adfc648bde8c2c31f280594fc to your computer and use it in GitHub Desktop.
Save aspose-com-gists/691bd86adfc648bde8c2c31f280594fc to your computer and use it in GitHub Desktop.
Generate Barcode with Logo using C#
// This code example demonstrates how to generate a barcode with an image instead of code text.
// Create an instance of BarcodeGenerator class
// Set the barcode symbology
// Set the barcode text
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.EAN13, "1234567890");
// Set QR code size value in pixels
generator.Parameters.Barcode.XDimension.Pixels = 10;
// Generate Barcode image and store it in a Bitmap
Bitmap barcode = generator.GenerateBarCodeImage();
// Load the logo or other image as Bitmap
Bitmap picture = (Bitmap)Image.FromFile(@"D:\Files\BarCode\aspose-logo.png");
// Create a new empty image with new Calculated height & width
Bitmap output = new Bitmap(Math.Max(barcode.Width, picture.Width), barcode.Height + picture.Height);
// Get the Graphics object
using (Graphics g = Graphics.FromImage(output))
{
// Clear the canvas
g.Clear(Color.White);
// Draw the primary image (barcode image) on the canvas
g.DrawImage(picture, new PointF(30, 0));
// Draw the second image (logo image) on the canvas inside the barcode image
g.DrawImage(barcode, new PointF(0, picture.Height));
}
// Save the output image
output.Save(@"D:\Files\BarCode\output.jpg");
// This code example demonstrates how to generate a barcode with an image instead of code text.
// Create an instance of BarcodeGenerator class
// Set the barcode symbology
// Set the barcode text
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "1234567890");
// Set QR code size value in pixels
generator.Parameters.Barcode.XDimension.Pixels = 10
// Generate Barcode image and store it in a Bitmap
Bitmap barcode = generator.GenerateBarCodeImage();
// Load the logo or other image as Bitmap
Bitmap picture = (Bitmap)Image.FromFile(@"D:\Files\BarCode\logo.png");
// Create a new empty image with new Calculated height & width
Bitmap output = new Bitmap(Math.Max(barcode.Width, picture.Width), barcode.Height + picture.Height);
// Get the Graphics object
using (Graphics g = Graphics.FromImage(output))
{
// Clear the canvas
g.Clear(Color.White);
// Draw the primary image (barcode image) on the canvas
g.DrawImage(picture, new PointF(30, 0));
// Draw the second image (logo image) on the canvas inside the barcode image
g.DrawImage(barcode, new PointF(0, picture.Height));
}
// Save the output image
output.Save(@"D:\Files\BarCode\qr_output.jpg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment