Generate QR Codes in C# - Complete Tutorial for .NET Developers
IronQR is Iron Software's brand new .NET QR Code library. Leverage cutting-edge machine learning techniques to read QR codes from any angle with high accuracy. Generate and customize new QR codes with ease! Get started with IronQR now!
Need to generate QR codes in your C# application? This tutorial shows you exactly how to create, customize, and verify QR codes using IronBarcode - from simple one-line implementations to advanced features like logo embedding and binary data encoding.
Whether you're building inventory systems, event ticketing platforms, or contactless payment solutions, you'll learn how to implement professional-grade QR code functionality in your .NET applications.
Quickstart: One-Line QR Code Creation with IronBarcodeReady to generate a QR Code fast? Here's how you can use IronBarcode's QRCodeWriter API to produce a QR code in just one line of code - customization is optional but powerful.
-
1Install IronBarcode with NuGet Package Manager
-
2Copy and run this code snippet.
var qr = QRCodeWriter.CreateQrCode("https://ironsoftware.com/", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium); qr.SaveAsPng("MyQR.png");C# -
3Deploy to test on your live environment
Start using IronBarcode in your project today with a free trial
Minimal Workflow (5 steps)
- Install IronBarcode via NuGet
- Create a QR code with one line:
QRCodeWriter.CreateQrCode() - Embed logos using
CreateQrCodeWithLogo() - Verify readability with
GeneratedBarcode.Verify() - Encode binary data for advanced applications
How Do I Install a QR Code Library in C#?
Install IronBarcode using the NuGet Package Manager with this simple command:
Alternatively, download the IronBarcode DLL directly and add it as a reference to your project.
Import Required Namespaces
Add these namespaces to access IronBarcode's QR code generation features:
using IronBarCode;Imports IronBarCodeHow Can I Create a Simple QR Code in C#?
Generate a QR code with just one line of code using IronBarcode's CreateQrCode method:
using IronBarCode;
// Generate a Simple BarCode image and save as PDF
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");Imports IronBarCode
' Generate a Simple BarCode image and save as PDF
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png")The CreateQrCode method accepts three parameters:
- Text content: The data to encode (supports URLs, text, or any string data)
- Size: Pixel dimensions for the square QR code (500x500 in this example)
- Error correction: Determines readability in suboptimal conditions (Low, Medium, Quartile, or High)
Higher error correction levels enable QR codes to remain readable even when partially damaged or obscured, though they result in denser patterns with more data modules.
A basic QR code containing "hello world" text, generated at 500x500 pixels with medium error correction
How Do I Add a Logo to My QR Code?
Embedding logos in QR codes enhances brand recognition while maintaining scannability. IronBarcode automatically positions and sizes logos to preserve QR code integrity:
using IronBarCode;
using IronSoftware.Drawing;
// You may add styling with color, logo images or branding:
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
// Logo will automatically be sized appropriately and snapped to the QR grid.
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png");Imports IronBarCode
Imports IronSoftware.Drawing
' You may add styling with color, logo images or branding:
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen)
' Logo will automatically be sized appropriately and snapped to the QR grid.
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png")The CreateQrCodeWithLogo method intelligently handles logo placement by:
- Automatically sizing the logo to maintain QR code readability
- Positioning it within the quiet zone to avoid data corruption
- Preserving the logo's original colors when changing QR code colors
This approach ensures your branded QR codes remain fully functional across all scanning devices and applications.
QR code featuring the Visual Studio logo, demonstrating IronBarcode's automatic logo sizing and positioning
How Can I Export QR Codes to Different Formats?
IronBarcode supports multiple export formats for different use cases. Export your QR codes as images, PDFs, or HTML files:
using IronBarCode;
// You may add styling with color, logo images or branding:
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
myQRCodeWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Save as PDF
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf");
// Also Save as HTML
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");Imports IronBarCode
' You may add styling with color, logo images or branding:
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
myQRCodeWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
' Save as PDF
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf")
' Also Save as HTML
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html")Each format serves specific purposes:
- PDF: Ideal for printable documents and reports
- HTML: Perfect for web integration without external dependencies
- PNG/JPEG: Standard image formats for versatile usage
How Do I Verify QR Code Readability After Customization?
Color modifications and logo additions can impact QR code scannability. Use the Verify() method to ensure your customized QR codes remain readable:
using IronBarCode;
using IronSoftware.Drawing;
using System;
// Verifying QR Codes
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode MyVerifiedQR = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
MyVerifiedQR.ChangeBarCodeColor(System.Drawing.Color.LightBlue);
if (!MyVerifiedQR.Verify())
{
Console.WriteLine("\t LightBlue is not dark enough to be read accurately. Lets try DarkBlue");
MyVerifiedQR.ChangeBarCodeColor(Color.DarkBlue);
}
MyVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html");
// open the barcode html file in your default web browser
System.Diagnostics.Process.Start("MyVerifiedQR.html");Imports Microsoft.VisualBasic
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System
' Verifying QR Codes
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private MyVerifiedQR As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
MyVerifiedQR.ChangeBarCodeColor(System.Drawing.Color.LightBlue)
If Not MyVerifiedQR.Verify() Then
Console.WriteLine(vbTab & " LightBlue is not dark enough to be read accurately. Lets try DarkBlue")
MyVerifiedQR.ChangeBarCodeColor(Color.DarkBlue)
End If
MyVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html")
' open the barcode html file in your default web browser
System.Diagnostics.Process.Start("MyVerifiedQR.html")The Verify() method performs a comprehensive scan test on your QR code. This ensures compatibility across different scanning devices and lighting conditions before deployment.
A successfully verified QR code in dark blue, demonstrating proper contrast for reliable scanning
How Can I Encode Binary Data in QR Codes?
QR codes excel at storing binary data efficiently. This capability enables advanced applications like encrypted data transfer, file sharing, and IoT device configuration:
using IronBarCode;
using System;
using System.Linq;
// Convert string to binary data
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/");
// Create QR code from binary content
QRCodeWriter.CreateQrCode(binaryData, 500).SaveAsPng("MyBinaryQR.png");
// Read and verify binary data integrity
var myReturnedData = BarcodeReader.Read("MyBinaryQR.png").First();
// Confirm data matches original
if (binaryData.SequenceEqual(myReturnedData.BinaryValue))
{
Console.WriteLine("Binary Data Read and Written Perfectly");
}
else
{
throw new Exception("Data integrity check failed");
}Imports IronBarCode
Imports System
Imports System.Linq
' Convert string to binary data
Dim binaryData As Byte() = System.Text.Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/")
' Create QR code from binary content
QRCodeWriter.CreateQrCode(binaryData, 500).SaveAsPng("MyBinaryQR.png")
' Read and verify binary data integrity
Dim myReturnedData = BarcodeReader.Read("MyBinaryQR.png").First()
' Confirm data matches original
If binaryData.SequenceEqual(myReturnedData.BinaryValue) Then
Console.WriteLine("Binary Data Read and Written Perfectly")
Else
Throw New Exception("Data integrity check failed")
End IfBinary encoding in QR codes offers several advantages:
- Efficiency: Stores data in compact binary format
- Versatility: Handles any data type (files, encrypted content, serialized objects)
- Integrity: Preserves exact byte sequences without encoding issues
This feature distinguishes IronBarcode from basic QR code libraries, enabling sophisticated data exchange scenarios in your applications.
QR code storing binary data, demonstrating IronBarcode's advanced encoding capabilities
How Do I Read QR Codes in C#?
IronBarcode provides flexible QR code reading capabilities. Here's the simplest approach:
using IronBarCode;
using System;
using System.Linq;
// Read QR code with optimized settings
BarcodeResults result = BarcodeReader.Read("QR.png", new BarcodeReaderOptions() {
ExpectBarcodeTypes = BarcodeEncoding.QRCode
});
// Extract and display the decoded value
if (result != null && result.Any())
{
Console.WriteLine(result.First().Value);
}
else
{
Console.WriteLine("No QR codes found in the image.");
}Imports IronBarCode
Imports System
Imports System.Linq
' Read QR code with optimized settings
Private result As BarcodeResults = BarcodeReader.Read("QR.png", New BarcodeReaderOptions() With {.ExpectBarcodeTypes = BarcodeEncoding.QRCode})
' Extract and display the decoded value
If result IsNot Nothing AndAlso result.Any() Then
Console.WriteLine(result.First().Value)
Else
Console.WriteLine("No QR codes found in the image.")
End IfFor more complex scenarios requiring fine-tuned control:
using IronBarCode;
using System;
using System.Linq;
// Configure advanced reading options
BarcodeReaderOptions options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Faster, // Optimize for speed
ExpectMultipleBarcodes = false, // Single QR code expected
ExpectBarcodeTypes = BarcodeEncoding.QRCode, // QR codes only
Multithreaded = true, // Enable parallel processing
MaxParallelThreads = 4, // Utilize multiple CPU cores
RemoveFalsePositive = true, // Filter out false detections
ImageFilters = new ImageFilterCollection() // Apply preprocessing
{
new AdaptiveThresholdFilter(), // Handle varying lighting
new ContrastFilter(), // Enhance contrast
new SharpenFilter() // Improve edge definition
}
};
// Read with advanced configuration
BarcodeResults result = BarcodeReader.Read("QR.png", options);Imports IronBarCode
Imports System
Imports System.Linq
' Configure advanced reading options
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Faster, ' Optimize for speed
.ExpectMultipleBarcodes = False, ' Single QR code expected
.ExpectBarcodeTypes = BarcodeEncoding.QRCode, ' QR codes only
.Multithreaded = True, ' Enable parallel processing
.MaxParallelThreads = 4, ' Utilize multiple CPU cores
.RemoveFalsePositive = True, ' Filter out false detections
.ImageFilters = New ImageFilterCollection() From { ' Apply preprocessing
New AdaptiveThresholdFilter(), ' Handle varying lighting
New ContrastFilter(), ' Enhance contrast
New SharpenFilter() ' Improve edge definition
}
}
' Read with advanced configuration
Dim result As BarcodeResults = BarcodeReader.Read("QR.png", options)These advanced reading options enable reliable QR code detection in challenging conditions like poor lighting, image distortion, or low-quality prints.
What's Next for QR Code Development?
Now that you've mastered QR code generation with IronBarcode, explore these advanced topics:
- Extract QR codes from PDF documents
- Implement batch QR code processing
- Apply image corrections for difficult scans
Download Resources
Access the complete source code and examples:
API Documentation
Explore the complete feature set in the API reference:
Alternative: IronQR for Advanced QR Applications
For projects requiring cutting-edge QR code capabilities, consider IronQR - Iron Software's specialized QR code library featuring machine learning-powered reading and advanced generation options.
Ready to implement QR codes in your .NET application? Start your free trial or download IronBarcode today.
Frequently Asked Questions
What is IronBarcode and how can it help with QR code generation?
IronBarcode is a .NET library by Iron Software designed for generating and customizing QR codes, allowing developers to implement professional-grade QR code functionality in .NET applications with features such as logo embedding and binary data encoding.
How can I create a QR code in C# using IronBarcode?
To create a QR code with IronBarcode, you can use the `QRCodeWriter.CreateQrCode` method. This method takes text content, size, and error correction level as parameters and generates a QR code that can be saved in various formats like PNG.
Can I customize the appearance of my QR code using IronBarcode?
Yes, IronBarcode allows for extensive customization of QR codes, including changing colors, embedding logos, and adjusting sizes. This customization helps maintain QR code integrity and enhances brand recognition.
How do I verify the readability of a customized QR code?
You can use IronBarcode's `Verify()` method to test the readability of a QR code, ensuring it is scannable across different devices and under various lighting conditions, even after applying customizations like color changes or logo additions.
What export formats are available for QR codes generated with IronBarcode?
IronBarcode supports exporting QR codes to multiple formats, including PNG, PDF, and HTML, catering to different use cases such as web integration, printed documents, and digital sharing.
How can I encode binary data in a QR code using IronBarcode?
You can use IronBarcode to efficiently encode binary data in QR codes, supporting advanced applications like encrypted data transfer and IoT device configuration by preserving exact byte sequences.
How can I read QR codes in C# with IronBarcode?
IronBarcode offers flexible QR code reading capabilities through methods like `BarcodeReader.Read`, supporting basic decoding and advanced configurations such as multithreading, to enhance accuracy and speed in various conditions.
What are the steps to install IronBarcode in a C# project?
To install IronBarcode, use the NuGet Package Manager with the command provided in the tutorial, or download the IronBarcode DLL directly and add it as a reference to your C# project.
How does IronBarcode handle logo placement in QR codes?
IronBarcode's `CreateQrCodeWithLogo` method automatically sizes and positions logos within the QR code's quiet zone, maintaining readability and avoiding data corruption. This ensures the QR code remains fully functional and scannable.
What are some advanced features of IronQR, Iron Software's specialized QR code library?
IronQR offers cutting-edge QR code capabilities including machine learning-powered reading and generation options, suitable for projects requiring advanced QR code applications beyond basic functionality.

Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.