IRONSOFTWAREHOME

Write QR Codes in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Introduction

With IronQR, developers can create QR codes for popular image formats and customize them with background colors, margins, logos, and even add them to PDFs. For advanced use, it also offers control over error correction and versions.

This article will explore key features of IronQR with examples, helping you understand how to use it for writing QR codes in C# and apply it effectively in your projects.

Table of Contents

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

First Step:
arrow pointer

Input Data

Text, URLs, Numbers

IronQR can convert a wide range of data types, including text, URLs, and numbers, into QR codes. Whether you're creating QR code links or text for marketing and communication, numeric codes for inventory management, or encoding binary data or streams into readable QR codes, IronQR provides all the support you need.

Additionally, the API is straightforward. The QrWriter class offers several overloads, enabling different types of data as input, reducing complexity and streamlining the process.

using IronQr;
using IronSoftware.Drawing;

string text = "Hello, World!";
string url = "https://ironsoftware.com/csharp/qr/";
string alphanumeric = "WATERSKU-12356";

// Create QR code
QrCode textQr = QrWriter.Write(text);
// Save QR code as a bitmap
AnyBitmap textQrImage = textQr.Save();
// Save QR code as file
textQrImage.SaveAs("textQr.png");

QrCode urlQr = QrWriter.Write(url);
AnyBitmap urlQrImage = urlQr.Save();
urlQrImage.SaveAs("urlQr.png");

QrCode alphanumericQr = QrWriter.Write(alphanumeric);
AnyBitmap alphanumericQrImage = alphanumericQr.Save();
alphanumericQrImage.SaveAs("alphanumericQr.png");

Binary & Streams

Similarly, we can convert binary data and streams into QR codes using the same Write method as mentioned earlier.

using IronQr;
using IronSoftware.Drawing;
using System.Text;

byte[] bytes = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/");

// Create QR code
QrCode bytesQr = QrWriter.Write(bytes);

// Save QR code as a bitmap
AnyBitmap qrImage = bytesQr.Save();

// Save QR code bitmap to file
qrImage.SaveAs("bytesQr.png");

The Write method has overloads that accept both byte arrays and streams as inputs. For streams, we can create a MemoryStream from the byte array and then convert it into a QR code. This is useful when users require more fine-grained control over data chunks, as streams can be more memory-efficient.

using IronQr;
using IronSoftware.Drawing;
using System.IO;
using System.Text;

MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/"));

// Create QR code
QrCode streamQr = QrWriter.Write(stream);

// Save QR code as a bitmap
AnyBitmap streamQrImage = streamQr.Save();

// Save QR code bitmap as file
streamQrImage.SaveAs("streamQr.png");

Export QR Codes

IronQR is flexible and adaptable to various use cases that require different file formats. You can save QR codes in multiple formats such as JPG, PNG, GIF, and TIFF using the SaveAs method.

Save as Image

The SaveAs method from AnyBitmap automatically detects the file format based on the provided file path. In this example, I specified a file path ending with .png.

Please note: When using the SaveAs method, please note that there is no default image format. If you enter an unrecognized extension or make a typo in the file path, the image will be saved with the incorrect extension.
using IronQr;
using IronSoftware.Drawing;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qr.png");

System.Drawing.Images

Converting images to the System.Drawing.Images object from Microsoft allows you to use the Bitmap class to save the QR code to a file path. In this example, the Save method saves the QR code as a PNG file to the path qrBitmap.png.

Please note: System.Drawing.Common is only supported on the Windows platform.
using IronQr;
using System.Drawing;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

// Save QR code as a bitmap
Bitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.Save("qrBitmap.png");

IronSoftware.Drawing

Due to the lack of cross-platform compatibility of System.Drawing.Common, developers may encounter issues when maintaining cross-platform applications. IronQR can utilize both System.Drawing.Common and IronSoftware.Drawing.

IronQR uses the AnyBitmap class from IronSoftware.Drawing, a universally compatible Bitmap class that implicitly casts to the following:

  • System.Drawing.Bitmap
  • System.Drawing.Image
  • SkiaSharp.SKBitmap
  • SixLabors.ImageSharp
  • Microsoft.Maui.Graphics.Platform.PlatformImage

With this powerful open-source library, IronQR achieves cross-platform support and compatibility with .NET 10, .NET 9, .NET 8, .NET 7, .NET 6, .NET Core, .NET Standard, and .NET Framework 4.6.2+. To learn more about the library, please refer to the IronSoftware.Drawing website.

Stamp on PDF

IronQR allows developers to stamp QR codes onto existing PDF documents, making it easy for others to quickly access links or additional resources. Stamping QR codes on both single and multiple pages is supported.

Stamp to a Single Page

After creating the QR code, call the StampToExistingPdfPage method from the QrCode object. This method requires the file path, coordinates (x and y), page number, and an optional password if the PDF is password-protected. Once the arguments are provided, the method stamps the QR code and saves the PDF.

Please note: This method is based on the PDF pages, with page numbering starting at 1 instead of 0.
using IronQr;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

string filepath = "example.pdf";
int x = 100;
int y = 150;
int page = 1;

// Stamp QR code to (100, 150) of the pdf on page 1
qr.StampToExistingPdfPage(filepath, x, y, page);

Stamp to Multiple Pages

Similar to the example above, the main difference is that the StampToExistingPdfPages method takes a list of page numbers instead of just one.

using IronQr;
using System.Collections.Generic;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

string filepath = "example.pdf";
int x = 100;
int y = 150;
List<int> pages = new List<int>();
pages.Add(1);
pages.Add(2);
pages.Add(3);
pages.Add(4);

// Stamp QR code to (100, 150) of the pdf on pages 1-4
qr.StampToExistingPdfPages(filepath, x, y, pages);

Output from Both Examples

alt text


QR Code Options

IronQR offers extensive customization options for fine-tuning QR code behavior and functionality. The QrOptions class provides several parameters, such as version control, encoding type, character encoding, and error correction levels. Let's explore these options in more detail.

Encoding

IronQR supports multiple types of QR codes for both creation and reading. Below are the supported types:

  • QRCode: This is the standard QR code, commonly used today. It can store up to 7,089 numeric characters or 4,296 alphanumeric characters.
  • MicroQRCode: A smaller version of the standard QR code, it can store up to 35 numeric characters or 21 alphanumeric characters.
  • RMQRCode: The Rectangular Micro QR Code is a compact version of the QR code, offering flexibility in its aspect ratio.
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change encoding to micro QR code
    Encoding = IronQr.Enum.QrEncoding.MicroQRCode,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");

Error Correction

IronQR uses standard QR error correction to ensure that all QR codes produced are fault-tolerant and reliable, even in harsh conditions. Additionally, IronQR allows you total control over error correction level for further fine-tuning.

There are four levels of error correction available, provided by QrErrorCorrectionLevel:

  • Highest: 30% error correction
  • High: 25% error correction
  • Medium: 15% error correction
  • Low: 7% error correction
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change error correction level to medium
    ErrorCorrectionLevel = QrErrorCorrectionLevel.Medium,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");

Higher error correction provides greater fault tolerance when reading the QR code, making it more likely to be scanned at lower resolutions compared to one with low error correction. You may test out based on your use cases.

alt text

QR Code Version

You can adjust the QR code version to store more data. Higher versions are ideal for inventory or logistics, while lower versions work well for smaller data, like short URLs. Simply change the Version property in the QrOptions object and pass it to the Write method to generate the QR code as needed.

using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change QR code version to 40
    Version = 40,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");

alt text

As you can see from the output, version 40 of the QR code is highly complex and dense compared to version 5.

Lower versions require more precise scanning and may be difficult to scan without higher-resolution scanners. However, higher versions are easier to scan, even with lower-resolution cameras. For a more detailed guide on choosing the QR version based on capacity, please refer to the QR version list.

Character Encoding

This option determines how the QR code is encoded. In our example, we changed it to 'UTF-32', while the default character encoding is 'ISO-8859-1.'

using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change character encoding to UTF-32
    CharacterEncoding = "UTF-32"
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");

QR Code Styling

In addition to its easy-to-use methods and flexibility in handling input data, IronQR offers many options for customizing and styling QR codes to make them unique. The QrStyleOptions class provides various parameters for customizing all aspects of a QR code. Let's explore the available options.

Resize

To resize the QR code, you can set the Dimensions property of the QrStyleOptions object and then pass it to the Save method. By default, the QR code is saved at 300px. In this example, we saved the QR code at 600px instead of 300px.

using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change the dimensions to 600px
    Dimensions = 600,
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLResized.png");

alt text

Margins & Borders

To adjust the margins and borders, we can use the Margins property of the QrStyleOptions class. This property controls the margins of the QR code on all sides, with a default value of 10px. In our example, we set the margin to 20px.

using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change margins to 20px
    Margins = 20
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");

alt text

Change Margins for Each Side

IronQR also allows users to specify different margins for each side, providing more fine-grained control.

using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change margins
    MarginBottom = 30,
    MarginTop = 100,
    MarginRight = 40,
    MarginLeft = 20,
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");

Recolor

We can add colors to the QR code and its background using the QrStyleOptions class. Customizing colors makes the QR code more unique and eye-catching. You can change the color using the Color and BackgroundColor properties. Be sure to import IronSoftware.Drawing for a list of available colors to assign.

using IronQr;
using IronSoftware.Drawing;

// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");

// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
    Logo = new QrLogo(logo, 50, 50, 10),
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");

alt text

In addition to colors and dimensions, you can also apply your company logo to the QR code. This helps users immediately recognize and associate the QR code with your brand. The Logo property makes it easy to customize a QR code by adding your company's logo.

using IronQr;
using IronSoftware.Drawing;

// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");

// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
    Logo = new QrLogo(logo, 50, 50, 10),
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");

alt text

The QrLogo class allows further customization of the logo's appearance. Below are the available properties:

  • Bitmap: Represents the image you want to use as the logo.
  • Width: Represents the logo's width. The default value is 0.
  • Height: Represents the logo's height. The default value is 0.
  • CornerRadius: Represents the radius for rounding the logo's corners. By default, it's set to 0, meaning the logo will have square corners.
using IronQr;
using IronSoftware.Drawing;

class Program
{
    static void Main()
    {
        QrStyleOptions styleOptions = new QrStyleOptions
        {
            Logo = new QrLogo
            {
                Bitmap = AnyBitmap.FromFile("path/to/logo.png"),
                Width = 50,
                Height = 50,
                CornerRadius = 5
            }
        };

        QrCode qr = QrWriter.Write("Customized Logo Example");

        AnyBitmap img = qr.Save(styleOptions);
        img.SaveAs("example-customized-logo-qr.png");
    }
}
C#

Checking Fault Tolerance

Along with extensive flexibility in file formats and customizations, the flexibility extends to debugging and error-handling aspects. IronQR provides various tools for developers to handle exceptions and write unit tests to verify applications.

CheckSums

QR codes may sometimes become damaged, but IronQR includes built-in checksums and data correction to keep them functional. It uses the Reed-Solomon error correction algorithm, ensuring that QR codes remain fault-tolerant.

Detailed Error Messages

IronQR provides detailed error messages that help users quickly identify issues. These messages contain a list of specific exceptions, making debugging and problem-solving more straightforward. Below is a list of IronQrException used by the library.

  • IronQrEncodingException: A subclass of IronQrException, this error occurs when there is an issue with writing the QR code. For instance, it will appear if a user attempts to create a QR code from an empty string.

    alt text

  • IronQrFileException: A subclass of IronQrException, this error occurs when a file-related issue arises.

  • IronQrPdfPasswordException: A subclass of IronQrException, this error occurs when the PDF a user is trying to stamp is password-protected, and either no password or an incorrect password is provided. It also covers other PDF-related errors, such as when the PDF cannot be opened, as shown in the example.

    alt text

Conclusion

IronQR provides a comprehensive set of methods for generating and customizing QR codes within .NET applications. With its robust features, developers can easily create QR codes with various data encodings, visual styles, and error correction levels. The library's support for diverse output formats and seamless integration into existing documents makes it a versatile tool for any QR code project. Whether you need basic QR codes or advanced, branded solutions, IronQR offers the flexibility and functionality to meet your needs efficiently.

To learn more, check out the IronQR documentation, start exploring with a free trial, and review the licensing options to see which plan best suits your needs.

Frequently Asked Questions

How do I create QR codes with custom error correction in C# using IronQR?

IronQR allows developers to customize the error correction level for QR codes using the QrOptions class. You can set the ErrorCorrectionLevel property to one of four levels: Low, Medium, High, or Highest, depending on the degree of error correction required.

Can IronQR encode different types of data into QR codes?

Yes, IronQR supports encoding a wide range of data, including text, URLs, numbers, binary data, and streams, into QR codes. This flexibility allows developers to create QR codes for various applications, such as linking to websites or managing inventory.

What file formats can I export QR codes to using IronQR?

IronQR provides the ability to save QR codes in multiple file formats, including JPG, PNG, GIF, and TIFF. To save a QR code, use the SaveAs method from the AnyBitmap class, specifying the desired file path and format.

How can I customize the appearance of QR codes with IronQR?

IronQR offers various styling options through the QrStyleOptions class, allowing you to resize QR codes, adjust margins and borders, change colors, and add a company logo to make the QR code unique and branded.

Can I stamp QR codes onto existing PDF documents using IronQR?

Yes, IronQR provides functionality to stamp QR codes onto existing PDF documents. You can stamp a QR code onto a single page or multiple pages using the StampToExistingPdfPage or StampToExistingPdfPages methods, respectively.

What is the advantage of using IronSoftware.Drawing with IronQR?

IronSoftware.Drawing provides cross-platform compatibility for IronQR, supporting a wide range of .NET versions and platforms. It offers a universally compatible Bitmap class, AnyBitmap, which can be converted to multiple image formats and used with cross-platform applications.

How can I handle exceptions when generating QR codes with IronQR?

IronQR provides detailed error messages and uses specific exception classes, such as IronQrEncodingException and IronQrFileException, to help developers identify and handle errors during QR code generation. This aids in debugging and ensuring the robustness of the application.

Is it possible to change the character encoding of QR codes with IronQR?

Yes, you can set the character encoding for QR codes using the CharacterEncoding property of the QrOptions class. For example, you can specify 'UTF-32' for special character support, enhancing the QR code's functionality across different languages and scripts.

How can I control the QR code version in IronQR?

In IronQR, you can specify the QR code version to store varying amounts of data. This is controlled via the Version property in the QrOptions class, where higher versions store more data, suitable for applications like inventory management, while lower versions are ideal for simpler uses.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 74,386Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronQR
nuget.org/packages/IronQR/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronQR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronQR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronQR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required