We commonly use barcodes to represent encoded data or information about a product or a company in a machine-readable form. Normally, we use barcodes with text labels. However, we can also generate barcodes with company logos or images programmatically in .NET applications. In this article, we will learn how to generate a barcode with a logo using C#.
The article shall cover the following topics:
- C# API to Generate Barcode with Logo
- Generate Barcode with Logo in C#
- Generate QR Code with Logo using C#
C# API to Generate Barcode with Logo
For generating barcodes with logos or images, we will be using the Aspose.BarCode for .NET API. It allows us to generate and recognize a wide range of 1D & 2D barcode types. Please either download the DLL of the API or install it using NuGet.
PM> Install-Package Aspose.BarCode
Generate Barcode with Logo in C#
We can generate a barcode with a logo or an image by following the steps given below:
- Firstly, create an instance of the BarcodeGenerator class with the EncodeType and text to encode as arguments.
- Optionally, set the barcode size value in pixels.
- Next, generate a Barcode image using the GenerateBarCodeImage() method and store it in a Bitmap.
- Then, load the logo image as Bitmap.
- After that, create a new empty Bitmap image with the height of the logo and the generated barcode image.
- Next, initialize the Graphics class object using the FromImage() method. It takes an empty bitmap object as an argument.
- Then, clear the canvas using the Clear() method.
- Now, call the DrawImage() method to draw the barcode image on the canvas.
- After that, call the DrawImage() method again to draw the logo image on the canvas.
- Finally, save the output using the Image.Save() method. It takes the output file path as an argument.
The following code example demonstrates how to generate a barcode with a logo image using C#.
Generate QR Code with Logo using C#
Similarly, we can also generate a QR code with a logo or an image by following the steps mentioned earlier. However, we need to set the EncodeType as QR in the first step.
The following code example demonstrates how to generate a QR code with a logo image using C#.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
In this article, we have learned how to generate a barcode with a logo image. We have also seen how to generate a QR code with an image programmatically. Besides, you can learn more about Aspose.BarCode for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.