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

When generating 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, you will learn how to achieve this task programmatically in C# and VB.NET using Spire.Barcode for .NET library.

Install Spire.Barcode for .NET

To begin with, you need to add the DLL files included in the Spire.Barcode for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Barcode

Note: This feature relies on a commercial license. If you want to test it, please go to the end of this article to request a temporary license.

Generate QR Code with a Logo Image in C# and VB.NET

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

  • Create a BarcodeSettings object.
  • Set barcode type, error correction level and data etc. using BarcodeSettings.Type, BarcodeSettings.QRCodeECL and BarcodeSetting.Data properties.
  • Set logo image using BarcodeSettings.QRCodeLogoImage property.
  • Create a BarCodeGenerator object based on the settings.
  • Generate QR code image using BarCodeGenerator.GenerateImage() method.
  • Save the image using Image.Save() method.
  • C#
  • VB.NET
using Spire.Barcode;
using Spire.License;
using System.Drawing;

namespace AddLogoToQR
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load license
            Spire.License.LicenseProvider.SetLicenseFileFullPath("license.elic.xml");

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

            //Set barcode type, error correction level, data, etc.
            settings.Type = BarCodeType.QRCode;
            settings.QRCodeECL = QRCodeECL.M;
            settings.ShowText = false;
            settings.X = 2.5f;
            string data = "www.e-iceblue.com";
            settings.Data = data;
            settings.Data2D = data;

            //Set logo image
            settings.QRCodeLogoImage = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");

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

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

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.