Generate Barcode with Logo using C#

Generate Barcode with Logo using C#.

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:

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:

  1. Firstly, create an instance of the BarcodeGenerator class with the EncodeType and text to encode as arguments.
  2. Optionally, set the barcode size value in pixels.
  3. Next, generate a Barcode image using the GenerateBarCodeImage() method and store it in a Bitmap.
  4. Then, load the logo image as Bitmap.
  5. After that, create a new empty Bitmap image with the height of the logo and the generated barcode image.
  6. Next, initialize the Graphics class object using the FromImage() method. It takes an empty bitmap object as an argument.
  7. Then, clear the canvas using the Clear() method.
  8. Now, call the DrawImage() method to draw the barcode image on the canvas.
  9. After that, call the DrawImage() method again to draw the logo image on the canvas.
  10. 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 Barcode with Logo in 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#.

Generate QR Code with Logo using C#

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

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.

See Also