How to Generate QR Codes in C# with a NuGet Package
Generating QR codes in .NET applications has never been more straightforward. With the right NuGet package, you can create QR codes, customize their appearance, and save them to multiple output formats in just a few lines of code. IronQR delivers enterprise-grade QR code generation with cross-platform support for .NET Core, .NET Framework, and .NET 5-10.
This tutorial demonstrates how to install the IronQR NuGet package and start generating QR codes immediately. Whether you are building inventory systems, event ticketing platforms, or marketing applications, IronQR provides the tools needed for professional QR code implementation.
How Do You Install a QR Code NuGet Package?
Installing IronQR through NuGet Package Manager takes seconds. Open the NuGet Package Manager Console in Visual Studio and run the following command, or use the dotnet add package command for CLI environments:
Install-Package IronQR
The NuGet package automatically handles all dependencies, ensuring compatibility with your target frameworks. IronQR supports .NET Framework 4.6.2+, .NET Core 2.0+, and .NET 5-10, making it a versatile library for any Visual Studio project.
Before writing any code, you need a free trial license key. Set it early in your application startup so all subsequent calls are authenticated:
using IronQr;
// Set license key before any IronQR operation
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
using IronQr;
// Set license key before any IronQR operation
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
Imports IronQr
' Set license key before any IronQR operation
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
With the license key in place, your application is ready to generate, read, and customize QR codes without watermarks on output images.
How Do You Generate Your First QR Code?
Creating your first QR code requires minimal code. The QrWriter class handles QR code generation with sensible defaults that work well for most use cases:
using IronQr;
using IronSoftware.Drawing;
// Generate a QR code from text data
QrCode myQr = QrWriter.Write("Hello World");
// Save QR code as bitmap image
AnyBitmap qrImage = myQr.Save();
// Export to PNG file
qrImage.SaveAs("hello-qr.png");
using IronQr;
using IronSoftware.Drawing;
// Generate a QR code from text data
QrCode myQr = QrWriter.Write("Hello World");
// Save QR code as bitmap image
AnyBitmap qrImage = myQr.Save();
// Export to PNG file
qrImage.SaveAs("hello-qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Generate a QR code from text data
Dim myQr As QrCode = QrWriter.Write("Hello World")
' Save QR code as bitmap image
Dim qrImage As AnyBitmap = myQr.Save()
' Export to PNG file
qrImage.SaveAs("hello-qr.png")
QR Code Output

The QrWriter.Write() method accepts string data and returns a QrCode object containing the QR symbol. The Save() method converts this to an AnyBitmap, which supports encoding to various image formats or exporting vector data for a XAML Path. This approach works across Windows, macOS, and Linux without platform-specific dependencies -- unlike libraries relying on System.Drawing that are Windows-only starting with .NET 6.
The three-line pattern above covers the most common scenario: encode a string, get a bitmap, write a file. For production use, you will likely pass URL strings, product identifiers, or JSON payloads rather than plain text.
How Do You Choose the Right Error Correction Level?
QR codes support four error correction levels defined in the ISO/IEC 18004 QR code standard that determine how much damage a code can sustain while remaining scannable. IronQR supports all four levels through the QrOptions class:
| Level | Recovery Capacity | Best For |
|---|---|---|
| L (Low) | ~7% | Clean environments, maximum data density |
| M (Medium) | ~15% | General use (default) |
| Q (Quartile) | ~25% | Industrial applications |
| H (High) | ~30% | Logos, outdoor signage, partial occlusion |
using IronQr;
using IronSoftware.Drawing;
// Configure high error correction level
var options = new QrOptions(QrErrorCorrectionLevel.High);
// Generate QR code with options
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/", options);
AnyBitmap image = qr.Save();
image.SaveAs("high-correction-qr.png");
using IronQr;
using IronSoftware.Drawing;
// Configure high error correction level
var options = new QrOptions(QrErrorCorrectionLevel.High);
// Generate QR code with options
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/", options);
AnyBitmap image = qr.Save();
image.SaveAs("high-correction-qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Configure high error correction level
Dim options As New QrOptions(QrErrorCorrectionLevel.High)
' Generate QR code with options
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/", options)
Dim image As AnyBitmap = qr.Save()
image.SaveAs("high-correction-qr.png")
Output

Higher error correction levels create denser QR symbols with more raw modules, enabling the code to remain readable even when partially obscured or damaged. For codes that will be printed on packaging or embedded in logos, Level H is the right choice. For digital-only display where damage is not a concern, Level M balances data capacity and reliability.
Choosing the wrong level is a common source of scan failures in production. If your QR codes will appear on physical materials or at varying distances from cameras, use Level Q or H and verify the output with multiple scanner applications before deploying.
How Do You Customize QR Code Appearance?
IronQR provides extensive styling options through QrStyleOptions, enabling custom colors, dimensions, margins, and logo embedding. Branded QR codes perform better in marketing contexts because they associate the code visually with a known identity:
using IronQr;
using IronSoftware.Drawing;
// Create styled QR code with custom colors
var styleOptions = new QrStyleOptions
{
Dimensions = 300, // Width and height in pixels
Margins = 10, // Quiet zone in pixels
Color = Color.DarkBlue,
BackgroundColor = Color.White
};
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
AnyBitmap styledImage = qr.Save(styleOptions);
styledImage.SaveAs("styled-qr.png");
using IronQr;
using IronSoftware.Drawing;
// Create styled QR code with custom colors
var styleOptions = new QrStyleOptions
{
Dimensions = 300, // Width and height in pixels
Margins = 10, // Quiet zone in pixels
Color = Color.DarkBlue,
BackgroundColor = Color.White
};
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
AnyBitmap styledImage = qr.Save(styleOptions);
styledImage.SaveAs("styled-qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Create styled QR code with custom colors
Dim styleOptions As New QrStyleOptions With {
.Dimensions = 300, ' Width and height in pixels
.Margins = 10, ' Quiet zone in pixels
.Color = Color.DarkBlue,
.BackgroundColor = Color.White
}
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
Dim styledImage As AnyBitmap = qr.Save(styleOptions)
styledImage.SaveAs("styled-qr.png")
Styled QR Output

The Dimensions property sets both width and height in pixels. The Margins property controls the quiet zone -- the white border surrounding the QR symbol that scanners use to locate the code boundary. Reducing margins below the recommended 4-module minimum can cause scan failures on older devices.
Adding logos to QR codes enhances brand recognition. The styling system automatically positions logos while maintaining scannability -- a significant advantage over open-source alternatives that require manual placement calculations.
How Do You Save QR Codes to Different Output Formats?
IronQR supports multiple output formats including PNG, JPEG, GIF, TIFF, BMP, and SVG. The SaveAs method automatically detects the format from the file extension:
using IronQr;
using IronSoftware.Drawing;
QrCode qr = QrWriter.Write("Format demonstration");
AnyBitmap image = qr.Save();
// Save to raster image formats
image.SaveAs("qr-output.png");
image.SaveAs("qr-output.jpg");
image.SaveAs("qr-output.gif");
// Get as byte array for HTTP responses or database storage
byte[] pngBytes = image.ExportBytes();
using IronQr;
using IronSoftware.Drawing;
QrCode qr = QrWriter.Write("Format demonstration");
AnyBitmap image = qr.Save();
// Save to raster image formats
image.SaveAs("qr-output.png");
image.SaveAs("qr-output.jpg");
image.SaveAs("qr-output.gif");
// Get as byte array for HTTP responses or database storage
byte[] pngBytes = image.ExportBytes();
Imports IronQr
Imports IronSoftware.Drawing
Dim qr As QrCode = QrWriter.Write("Format demonstration")
Dim image As AnyBitmap = qr.Save()
' Save to raster image formats
image.SaveAs("qr-output.png")
image.SaveAs("qr-output.jpg")
image.SaveAs("qr-output.gif")
' Get as byte array for HTTP responses or database storage
Dim pngBytes As Byte() = image.ExportBytes()
Multiple QR Code Output Formats

The ExportBytes() method is particularly useful in web applications where you need to return a QR code image over HTTP without writing to disk. You can write the byte array directly to a response stream or store it in a database column for on-demand retrieval.
For embedding QR codes in PDF documents, IronQR provides the StampToExistingPdfPage method, enabling direct QR code placement on existing documents. This works natively without additional PDF libraries, which matters in microservices environments where you want to minimize dependency count.
How Do You Compare the IronQR NuGet Package with QRCoder?
The QRCoder library is a popular open-source option for QR code generation in .NET. Developers who have used QRCoder are familiar with its multi-step API involving QRCodeGenerator, QRCodeData, and a separate rendering class such as PngByteQRCode. IronQR simplifies this to a single QrWriter.Write() call.
| Feature | IronQR | QRCoder |
|---|---|---|
| Cross-Platform Rendering | Full .NET 5-10 support | Windows-only for bitmap rendering |
| ML-Powered Reading | 99.9% accuracy detection | Generation only, no reading |
| PDF Integration | Native stamping support | Requires additional libraries |
| Commercial Support | 24/5 engineering support | Community only |
| Logo Embedding | Built-in, auto-positioned | Manual overlay required |
QRCoder works well for basic generation in Windows environments. IronQR's machine learning model provides superior QR code reading from any angle -- critical for applications processing user-submitted images where the input quality cannot be controlled. The single-method API also reduces the lines of code needed to ship a working feature.
For teams migrating from QRCoder, see the QRCoder to IronQR migration guide for a side-by-side API mapping.
How Do You Encode Binary Data in a QR Code?
Beyond text, IronQR supports encoding byte arrays for binary QR code payloads. This is useful for encrypted tokens, serialized objects, or raw binary identifiers that cannot be represented as UTF-8 strings:
using IronQr;
using IronSoftware.Drawing;
// Encode binary data -- useful for encrypted payloads or binary identifiers
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes("Binary content example");
QrCode qr = QrWriter.Write(binaryData);
qr.Save().SaveAs("binary-qr.png");
using IronQr;
using IronSoftware.Drawing;
// Encode binary data -- useful for encrypted payloads or binary identifiers
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes("Binary content example");
QrCode qr = QrWriter.Write(binaryData);
qr.Save().SaveAs("binary-qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Encode binary data -- useful for encrypted payloads or binary identifiers
Dim binaryData As Byte() = System.Text.Encoding.UTF8.GetBytes("Binary content example")
Dim qr As QrCode = QrWriter.Write(binaryData)
qr.Save().SaveAs("binary-qr.png")
Output

Binary encoding enables you to include encrypted payloads, serialized objects, or any binary content within QR symbols. The scanner on the receiving end must know how to interpret the binary payload -- this is common in access control systems where the QR code contains a signed token rather than a human-readable URL.
Keep in mind that binary data produces denser QR symbols than equivalent text data. If the payload size is a concern for scan reliability at distance, apply Level H error correction and test with the smallest camera you expect users to have.
How Do You Read QR Codes in C#?
IronQR handles both writing and reading. The QrReader class accepts image files, bitmaps, and camera frames, making it suitable for both batch processing and real-time scanning scenarios:
using IronQr;
using IronSoftware.Drawing;
// Load an existing image containing a QR code
var inputImage = AnyBitmap.FromFile("qr-to-read.png");
// Read all QR codes in the image
QrReadResult readResult = QrReader.Read(inputImage);
foreach (QrResult result in readResult.QrCodes)
{
// Access the decoded value
Console.WriteLine($"Decoded: {result.Value}");
}
using IronQr;
using IronSoftware.Drawing;
// Load an existing image containing a QR code
var inputImage = AnyBitmap.FromFile("qr-to-read.png");
// Read all QR codes in the image
QrReadResult readResult = QrReader.Read(inputImage);
foreach (QrResult result in readResult.QrCodes)
{
// Access the decoded value
Console.WriteLine($"Decoded: {result.Value}");
}
Imports IronQr
Imports IronSoftware.Drawing
' Load an existing image containing a QR code
Dim inputImage = AnyBitmap.FromFile("qr-to-read.png")
' Read all QR codes in the image
Dim readResult As QrReadResult = QrReader.Read(inputImage)
For Each result As QrResult In readResult.QrCodes
' Access the decoded value
Console.WriteLine($"Decoded: {result.Value}")
Next
The ML-powered reading engine processes images at any orientation and handles partial damage up to the error correction threshold. For production reading scenarios, review the QR code reading tutorial for guidance on handling low-quality inputs, multi-code images, and scan mode configuration.
How Do You Use IronQR in an ASP.NET Core Application?
Web applications frequently need to generate QR codes on demand -- for user account links, one-time login codes, or payment requests. The following example shows how to serve a QR code image directly from an ASP.NET Core minimal API endpoint:
using IronQr;
using IronSoftware.Drawing;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Set license key at application startup
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
// Return a QR code PNG for a given URL parameter
app.MapGet("/qr", (string data) =>
{
QrCode qr = QrWriter.Write(data);
AnyBitmap image = qr.Save();
byte[] pngBytes = image.ExportBytes();
return Results.File(pngBytes, "image/png");
});
app.Run();
using IronQr;
using IronSoftware.Drawing;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Set license key at application startup
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
// Return a QR code PNG for a given URL parameter
app.MapGet("/qr", (string data) =>
{
QrCode qr = QrWriter.Write(data);
AnyBitmap image = qr.Save();
byte[] pngBytes = image.ExportBytes();
return Results.File(pngBytes, "image/png");
});
app.Run();
Imports IronQr
Imports IronSoftware.Drawing
Dim builder = WebApplication.CreateBuilder(args)
Dim app = builder.Build()
' Set license key at application startup
IronQr.License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
' Return a QR code PNG for a given URL parameter
app.MapGet("/qr", Function(data As String)
Dim qr As QrCode = QrWriter.Write(data)
Dim image As AnyBitmap = qr.Save()
Dim pngBytes As Byte() = image.ExportBytes()
Return Results.File(pngBytes, "image/png")
End Function)
app.Run()
This pattern works in ASP.NET Core minimal APIs and standard MVC controllers alike. The ExportBytes() call avoids writing temporary files to disk, which is important in containerized deployments where the filesystem may be read-only or ephemeral.
For a full ASP.NET Core integration walkthrough, see the ASP.NET Core QR code generator tutorial. A Blazor-specific guide is also available in the Blazor QR code generator tutorial.
How Do You Add a Margin and Resize a QR Code Image?
Controlling dimensions and quiet zones is essential for print-quality output. IronQR exposes both through QrStyleOptions, and dedicated how-to guides cover each in detail:
using IronQr;
using IronSoftware.Drawing;
// Specify dimensions and quiet zone for print output
var printOptions = new QrStyleOptions
{
Dimensions = 600, // High resolution for print
Margins = 20 // Generous quiet zone for reliable scanning
};
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
AnyBitmap printImage = qr.Save(printOptions);
printImage.SaveAs("print-ready-qr.png");
using IronQr;
using IronSoftware.Drawing;
// Specify dimensions and quiet zone for print output
var printOptions = new QrStyleOptions
{
Dimensions = 600, // High resolution for print
Margins = 20 // Generous quiet zone for reliable scanning
};
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
AnyBitmap printImage = qr.Save(printOptions);
printImage.SaveAs("print-ready-qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Specify dimensions and quiet zone for print output
Dim printOptions As New QrStyleOptions With {
.Dimensions = 600, ' High resolution for print
.Margins = 20 ' Generous quiet zone for reliable scanning
}
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
Dim printImage As AnyBitmap = qr.Save(printOptions)
printImage.SaveAs("print-ready-qr.png")
For full guidance on sizing and margin requirements across different output media, see the how-to articles on resizing QR code images and adding margins to QR codes. The create QR code image guide covers the full image creation workflow from license activation to file output.
For specific QR code use cases -- including generating QR codes for business cards, building a dynamic QR code generator, and reading QR codes from images -- the dedicated articles cover each scenario with full code examples.
What Are Your Next Steps?
IronQR turns QR code generation from a multi-step process into a straightforward NuGet integration. You install the package, call QrWriter.Write(), and save the result -- three operations that cover the majority of real-world scenarios. Error correction levels, custom styling, PDF stamping, and ML-powered reading are all available through the same library.
The IronQR documentation provides the complete API reference, including advanced topics such as reading QR codes with scan modes, batch processing, and platform-specific deployment notes. The IronQR tutorials section includes step-by-step guides for .NET MAUI, VB.NET, and console applications.
Start a free trial to explore the full feature set without restrictions, or purchase a license for production deployment with 24/5 engineering support.
Frequently Asked Questions
How do you install the IronQR NuGet package?
Run dotnet add package IronQR in a terminal, or open the NuGet Package Manager Console in Visual Studio and run Install-Package IronQR. The package supports .NET Framework 4.6.2+, .NET Core 2.0+, and .NET 5-10.
How do you generate a QR code in C# with IronQR?
Call QrWriter.Write("your-data") to create a QrCode object, then call .Save() to get an AnyBitmap, and finally call .SaveAs("output.png") to write the file.
What output formats does IronQR support for QR codes?
IronQR supports PNG, JPEG, GIF, TIFF, BMP, and SVG. The SaveAs method detects the format from the file extension automatically. Use ExportBytes() to get a byte array for HTTP responses or database storage.
How do you customize the color and size of a QR code with IronQR?
Create a QrStyleOptions object and set Dimensions (pixels), Margins (quiet zone pixels), Color, and BackgroundColor. Pass this to qr.Save(styleOptions).
What error correction levels does IronQR support?
IronQR supports all four ISO/IEC 18004 levels via QrErrorCorrectionLevel: L (~7% recovery), M (~15%, default), Q (~25%), and H (~30%). Pass the level in a QrOptions object to QrWriter.Write().
How does IronQR compare to QRCoder for .NET?
IronQR provides cross-platform rendering on .NET 5-10 (QRCoder bitmap rendering is Windows-only), built-in ML-powered reading (QRCoder generates only), native PDF stamping, and a single-method API. QRCoder is a free open-source option for simple Windows-based generation.
Can you use IronQR to read QR codes from images?
Yes. Use QrReader.Read(AnyBitmap.FromFile("path")) to scan an image. The ML-powered engine handles any orientation and partial damage. Iterate over readResult.QrCodes to access each decoded result.Value.
How do you generate QR codes in an ASP.NET Core application?
Call QrWriter.Write(data) inside your controller or minimal API handler, then call image.ExportBytes() and return the byte array as a Results.File(pngBytes, "image/png") response. No temporary files are needed.



