C#/VB.NET: Generate QR Code with a Custom Logo Image

Alice Yang
2 min readOct 26, 2021

--

When you generate a QR code, you might want to add a custom image such as your company’s logo or your personal profile image to it. In this article, I will describe how to achieve this task programmatically in C# and VB.NET.

Add Reference

In order to generate QR code and add logo image, I will use Spire.Barcode for .NET API which supports generating and reading up to 39 kinds of 1D and 2D barcodes.

You can either download the API from here or install it via NuGet by selecting Tools > NuGet Package Manager > Package Manager Console and then adding the following code:

PM> Install-Package Spire.Barcode

Generate QR Code with a Custom Logo Image

The following are the steps to generate a QR code with a custom logo image:

1. Instantiate a BarcodeSettings object.
2. Specify barcode type, error correction level, barcode width and data etc. using BarcodeSettings.Type, BarcodeSettings.QRCodeECL, BarcodeSettings.X and BarcodeSetting.Data attributes etc.
3. Add a custom image to the QR code using BarcodeSettings.QRCodeLogoImage attribute.
4. Instantiate a BarCodeGenerator object.
5. Generate QR code image using BarCodeGenerator.GenerateImage() method.
6. Save the image using Image.Save() method.

C#

using Spire.Barcode;
using System.Drawing;

namespace GenerateQRCodeWithLogo
{
class Program
{
static void Main(string[] args)
{
//Load a license file if you have one
//Spire.License.LicenseProvider.SetLicenseFileFullPath("licensePath");

//Instantiate a BarcodeSettings object
BarcodeSettings settings = new BarcodeSettings();

//Specify barcode type, data, etc.
settings.Type = BarCodeType.QRCode;
settings.QRCodeECL = QRCodeECL.M;
settings.ShowText = false;
settings.X = 2.5f;
string data = "https://twitter.com";
settings.Data = data;
settings.Data2D = data;

//Add an image to QR code
settings.QRCodeLogoImage = Image.FromFile(@"C:\Users\Administrator\Desktop\Logo.png");

//Instantiate a BarCodeGenerator object
BarCodeGenerator generator = new BarCodeGenerator(settings);
//Generate QR image
Image image = generator.GenerateImage();
//Save the image
image.Save("QR.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
}

VB.NET

Imports Spire.Barcode

Namespace GenerateQRCodeWithLogo
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Load a license file if you have one
'Spire.License.LicenseProvider.SetLicenseFileFullPath("licensePath")

'Instantiate a BarcodeSettings object
Dim settings As BarcodeSettings = New BarcodeSettings()

'Specify barcode type, data, etc.
settings.Type = BarCodeType.QRCode
settings.QRCodeECL = QRCodeECL.M
settings.ShowText = False
settings.X = 2.5F
Dim data As String = "https://twitter.com"
settings.Data = data
settings.Data2D = data

'Add an image to QR code
settings.QRCodeLogoImage = Image.FromFile("C:\Users\Administrator\Desktop\Logo.png")

'Instantiate a BarCodeGenerator object
Dim generator As BarCodeGenerator = New BarCodeGenerator(settings)
'Generate QR image
Dim image As Image = generator.GenerateImage()
'Save the image
image.Save("QR.png", Drawing.Imaging.ImageFormat.Png)
End Sub
End Class
End Namespace

The generated QR code with logo image:

create QR code with logo image in c#

Get a Free Trial License

The library will generate an evaluation watermark on the barcode image, you can request a free 30 days trial license to remove the watermark from the image.

--

--

Alice Yang

Skilled senior software developers with five years of experience in all phases of software development life cycle using .NET, Java and C++ languages.