Generate QR Codes in C# - Complete Tutorial for .NET Developers
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 IronBarcode
Ready 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.
Get started making PDFs with NuGet now:
Install IronBarcode with NuGet Package Manager
Copy and run this code snippet.
var qr = QRCodeWriter.CreateQrCode("https://ironsoftware.com/", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium); qr.SaveAsPng("MyQR.png");Deploy to test on your live environment
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#?
Start using IronBarcode in your project today with a free trial.
Install IronBarcode using the NuGet Package Manager with this simple command:
Install-Package BarCode
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;
using System;
using System.Drawing;
using System.Linq;using IronBarCode;
using System;
using System.Drawing;
using System.Linq;Imports IronBarCode
Imports System
Imports System.Drawing
Imports System.LinqHow 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 QR code with text content
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium);
qrCode.SaveAsPng("MyQR.png");using IronBarCode;
// Generate a QR code with text content
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium);
qrCode.SaveAsPng("MyQR.png");Imports IronBarCode
' Generate a QR code with text content
Private qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium)
qrCode.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;
// Load logo image
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
// Create QR code with embedded logo
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
// Save the branded QR code
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png");using IronBarCode;
using IronSoftware.Drawing;
// Load logo image
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
// Create QR code with embedded logo
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
// Save the branded QR code
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png");Imports IronBarCode
Imports IronSoftware.Drawing
' Load logo image
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
' Create QR code with embedded logo
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
' Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen)
' Save the branded QR code
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;
using System.Drawing;
// Create QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen);
// Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf"); // PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html"); // Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png"); // PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg"); // JPEG imageusing IronBarCode;
using System.Drawing;
// Create QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen);
// Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf"); // PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html"); // Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png"); // PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg"); // JPEG imageImports IronBarCode
Imports System.Drawing
' Create QR code with logo
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
' Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen)
' Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf") ' PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html") ' Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png") ' PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg") ' JPEG imageEach 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;
using System.Drawing;
// Generate QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myVerifiedQR = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply light color (may affect readability)
myVerifiedQR.ChangeBarCodeColor(Color.LightBlue);
// Verify the QR code can still be scanned
if (!myVerifiedQR.Verify())
{
Console.WriteLine("LightBlue is not dark enough to be read accurately. Let's try DarkBlue");
myVerifiedQR.ChangeBarCodeColor(Color.DarkBlue);
}
// Save verified QR code
myVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html");
// Open in default browser
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "MyVerifiedQR.html",
UseShellExecute = true
});using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Drawing;
// Generate QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myVerifiedQR = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply light color (may affect readability)
myVerifiedQR.ChangeBarCodeColor(Color.LightBlue);
// Verify the QR code can still be scanned
if (!myVerifiedQR.Verify())
{
Console.WriteLine("LightBlue is not dark enough to be read accurately. Let's try DarkBlue");
myVerifiedQR.ChangeBarCodeColor(Color.DarkBlue);
}
// Save verified QR code
myVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html");
// Open in default browser
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "MyVerifiedQR.html",
UseShellExecute = true
});Imports IronBarCode
Imports IronSoftware.Drawing
Imports System
Imports System.Drawing
' Generate QR code with logo
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myVerifiedQR As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
' Apply light color (may affect readability)
myVerifiedQR.ChangeBarCodeColor(Color.LightBlue)
' Verify the QR code can still be scanned
If Not myVerifiedQR.Verify() Then
Console.WriteLine("LightBlue is not dark enough to be read accurately. Let's try DarkBlue")
myVerifiedQR.ChangeBarCodeColor(Color.DarkBlue)
End If
' Save verified QR code
myVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html")
' Open in default browser
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo With {
.FileName = "MyVerifiedQR.html",
.UseShellExecute = True
})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");
}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
Private 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.");
}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);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
Private options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Faster,
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode,
.Multithreaded = True,
.MaxParallelThreads = 4,
.RemoveFalsePositive = True,
.ImageFilters = New ImageFilterCollection() From {
New AdaptiveThresholdFilter(),
New ContrastFilter(),
New SharpenFilter()
}
}
' Read with advanced configuration
Private 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 with 99.99% accuracy and advanced generation options.
Ready to implement QR codes in your .NET application? Start your free trial or download IronBarcode today.
Frequently Asked Questions
How do I generate a QR code in C#?
You can generate a QR code in C# using IronBarcode's QRCodeWriter.CreateQrCode() method. This method allows you to pass your content, size, and error correction level to create a QR code efficiently.
What image formats can QR codes be exported to?
With IronBarcode, you can export QR codes to various formats, including PNG, JPEG, PDF, and HTML. Methods like SaveAsPng(), SaveAsJpeg(), SaveAsPdf(), and SaveAsHtmlFile() are available for this purpose.
How can I add a company logo to a QR code?
IronBarcode provides the CreateQrCodeWithLogo() method, where you can pass a QRCodeLogo object containing your logo image. The library ensures that the logo is correctly sized and positioned to keep the QR code readable.
What is QR code error correction and which level should I choose?
Error correction in QR codes allows them to remain scannable even if partially damaged. IronBarcode offers four levels: Low (7%), Medium (15%), Quartile (25%), and High (30%). Medium is suitable for most purposes, while High is ideal for challenging environments.
How do I verify the readability of a customized QR code?
You can use the Verify() method on a GeneratedBarcode object to ensure your customized QR code remains scannable after modifications like color changes or logo additions.
Can binary data be encoded in QR codes?
Yes, IronBarcode's CreateQrCode() method supports encoding byte arrays, allowing you to store binary data such as files or encrypted content within QR codes.
How do I read QR codes from images in C#?
To read QR codes from images in C#, utilize IronBarcode's BarcodeReader.Read() method. For optimized performance, specify BarcodeEncoding.QRCode in the BarcodeReaderOptions.
What is the maximum data capacity of a QR code?
IronBarcode-generated QR codes can hold up to 2,953 bytes, 4,296 alphanumeric characters, or 7,089 numeric digits, depending on the error correction level selected.
How can I change the color of a QR code while ensuring it remains scannable?
The ChangeBarCodeColor() method in IronBarcode allows you to alter the color of a QR code. Always use the Verify() method afterward to confirm that the QR code's readability is unaffected by the color change.
What features does a specialized QR code library offer?
IronQR, a specialized library from Iron Software, includes advanced features such as machine learning-powered QR code reading with 99.99% accuracy and robust generation capabilities tailored for complex applications.






