How to Customize and Add Logos to QR Codes

by Hairil Hasyimi Bin Omar

QR codes have gained popularity over traditional barcodes due to their higher data capacity and ease of scanning. They are especially valued in marketing for their customizability, including options for adding logos, changing colors, and incorporating other branding elements.

To meet this demand, IronBarcode offers a suite of features for customizing QR codes. Users can create QR codes with logos, change the color schemes, and add annotations. These capabilities are powered by IronDrawing, a free and open-source library.



C# NuGet Library for

Install with NuGet

Install-Package BarCode
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for

Install with NuGet

Install-Package BarCode
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronBarcode on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming with C#.

C# NuGet Library for nuget.org/packages/BarCode/
Install-Package BarCode

Consider installing the IronBarcode DLL directly. Download and manually install it for your project or GAC form: IronBarCode.zip

Manually install into your project

Download DLL

Create QR Codes With Logo Example

A QRCodeLogo object is required to embed the logo image while generating the QR code. The CreateQrCodeWithLogo method is also used to generate a QR code with a logo.

:path=/static-assets/barcode/content-code-examples/how-to/customize-qr-code-style-logo.cs
using IronBarCode;
using IronSoftware.Drawing;

AnyBitmap qrlogo = AnyBitmap.FromFile("ironbarcode_top.webp");

QRCodeLogo logo = new QRCodeLogo(qrlogo, 0, 0, 20f);

GeneratedBarcode QrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250);

QrCodeWithLogo.SaveAsPng("QrCodeWLogo2.png");
Imports IronBarCode
Imports IronSoftware.Drawing

Private qrlogo As AnyBitmap = AnyBitmap.FromFile("ironbarcode_top.webp")

Private logo As New QRCodeLogo(qrlogo, 0, 0, 20F)

Private QrCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250)

QrCodeWithLogo.SaveAsPng("QrCodeWLogo2.png")
VB   C#
QR Code With Logo

Let's examine the output QR code generated by the above code. We can see that the QR code features a logo in the center, with rounded edges.

To customize the logo, you need to fill in certain fields while creating a new QRCodeLogo object. Here are the explanations for the required fields:

  • Importing Image: You can import images in multiple ways, such as from AnyBitmap, Stream, Byte Array, relative filepath, or URI.
  • Image Dimensions: Specify the desired width and height of the logo image in pixels. If the image is too large for the QR code to be readable, an exception will be thrown. Use the value 0 to automatically determine the largest viable size.
  • Image Corners: Set the radius of the logo image's rounded corners. Use the default value 0 for square corners.

Finally, to export the generated QR code, simply invoke a save method. You have multiple export options, including image files, Streams, HTML and PDF.

Change Color of QR Code Example

Apart from the ability to add logo to your QR code, IronBarcode also enables users to further customize their QR code by changing its color. With our IronDrawing library, users can easily define their own colors using RGB values or Hex color codes and apply them to the QR code. Let's look at the code snippet that demonstrates this feature and the resulting QR code we obtain from running this code.

:path=/static-assets/barcode/content-code-examples/how-to/customize-qr-code-style-logo-color.cs
using IronBarCode;
using IronSoftware.Drawing;

AnyBitmap qrlogo = AnyBitmap.FromFile("ironbarcode_top.webp");

QRCodeLogo logo = new QRCodeLogo(qrlogo, 0, 0, 20f);

IronSoftware.Drawing.Color ColorFromRgb = new IronSoftware.Drawing.Color(51, 51, 153);

GeneratedBarcode QrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250);
GeneratedBarcode QrCodeWithLogoAndColor = QrCodeWithLogo.ChangeBarCodeColor(ColorFromRgb);
QrCodeWithLogoAndColor.SaveAsPng("ColorQrCodeWithLogo.png");
Imports IronBarCode
Imports IronSoftware.Drawing

Private qrlogo As AnyBitmap = AnyBitmap.FromFile("ironbarcode_top.webp")

Private logo As New QRCodeLogo(qrlogo, 0, 0, 20F)

Private ColorFromRgb As New IronSoftware.Drawing.Color(51, 51, 153)

Private QrCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250)
Private QrCodeWithLogoAndColor As GeneratedBarcode = QrCodeWithLogo.ChangeBarCodeColor(ColorFromRgb)
QrCodeWithLogoAndColor.SaveAsPng("ColorQrCodeWithLogo.png")
VB   C#
QR Code With Custom Logo and Color

The code snippet above extends a previous example on creating QR codes with a logo. It demonstrates how to change the QR code color using the ChangeBarCodeColor method, which takes an IronSoftware.Drawing.Color object as an input. You can create this object using RGB values, Hex codes, or predefined enums. Visit our "Create Color" code example to learn more.

Add QR Code Annotation Example

Another important aspect of customizing or styling a QR code is adding annotations within the QR code image. These annotations can either be the barcode value itself or custom text for promotional or marketing purposes.

Now, let's examine the implementation of these methods and the resulting QR code image generated by the code snippet below.

:path=/static-assets/barcode/content-code-examples/how-to/customize-qr-code-style-logo-color-annotation.cs
using IronBarCode;
using IronSoftware.Drawing;

AnyBitmap qrlogo = AnyBitmap.FromFile("ironbarcode_top.webp");

QRCodeLogo logo = new QRCodeLogo(qrlogo, 0, 0, 20f);

Color colorForBarcode = new Color(51, 51, 153); // color from RGB
Color annotationAboveBarcodeColor = new Color("#176feb");  // color from Hex
Font annotationAboveBarcodeFont = new Font("Candara", FontStyle.Bold, 15);
Color barcodeValueBelowBarcodeColor = new Color("#6e53bb");
Font barcodeValueBelowBarcodeFont = new Font("Cambria", FontStyle.Regular, 15);

GeneratedBarcode qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250);
GeneratedBarcode qrCodeWithLogoAndColor = qrCodeWithLogo.ChangeBarCodeColor(colorForBarcode);
GeneratedBarcode qrCodeWithAnnotation = qrCodeWithLogoAndColor.AddAnnotationTextAboveBarcode("IronBarcodeRocks!", annotationAboveBarcodeFont, annotationAboveBarcodeColor, 2).AddBarcodeValueTextBelowBarcode(barcodeValueBelowBarcodeFont, barcodeValueBelowBarcodeColor, 2);
qrCodeWithAnnotation.SaveAsPng("QRCodeWithAnnotation.png");
Imports IronBarCode
Imports IronSoftware.Drawing

Private qrlogo As AnyBitmap = AnyBitmap.FromFile("ironbarcode_top.webp")

Private logo As New QRCodeLogo(qrlogo, 0, 0, 20F)

Private colorForBarcode As New Color(51, 51, 153) ' color from RGB
Private annotationAboveBarcodeColor As New Color("#176feb") ' color from Hex
Private annotationAboveBarcodeFont As New Font("Candara", FontStyle.Bold, 15)
Private barcodeValueBelowBarcodeColor As New Color("#6e53bb")
Private barcodeValueBelowBarcodeFont As New Font("Cambria", FontStyle.Regular, 15)

Private qrCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", logo, 250)
Private qrCodeWithLogoAndColor As GeneratedBarcode = qrCodeWithLogo.ChangeBarCodeColor(colorForBarcode)
Private qrCodeWithAnnotation As GeneratedBarcode = qrCodeWithLogoAndColor.AddAnnotationTextAboveBarcode("IronBarcodeRocks!", annotationAboveBarcodeFont, annotationAboveBarcodeColor, 2).AddBarcodeValueTextBelowBarcode(barcodeValueBelowBarcodeFont, barcodeValueBelowBarcodeColor, 2)
qrCodeWithAnnotation.SaveAsPng("QRCodeWithAnnotation.png")
VB   C#
QR Code With Annotation

IronBarcode provides methods for setting the annotation's position (above or below the QR code) as well as its font family and color. Below are the available methods for this functionality:

  • AddAnnotationTextAboveBarcode: Adds annotation text above the QR code.
  • AddAnnotationTextBelowBarcode: Adds annotation text below the QR code.
  • AddBarcodeValueTextAboveBarcode: Adds the barcode value text above the QR code.
  • AddBarcodeValueTextBelowBarcode: Adds the barcode value text below the QR code.

Customizing Annotation and Barcode Value

All four methods mentioned above accept a custom font as an IronSoftware.Drawing.Font object, color as an IronSoftware.Drawing.Color object, and an integer to specify the top and bottom spacing of the text in pixels. Please note that these parameters are optional; if not specified, the default font, color, and spacing will be used.

In a nutshell, IronBarcode is an ideal tool for creating and customizing your QR code. Apart from the direct methods used for the customizations, IronBarcode also used our own IronDrawing as a helper library for anything related to image processing, which assumed to be more stable than depending on other outside libraries.

Hairil Hasyimi Bin Omar

Software Engineer

Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree in Chemical and Process Engineering.