IronBarcode Tutorials C# QR Code Generator Generate QR Codes in C# - Complete Tutorial for .NET Developers ByJacob Mellor November 5, 2018 Updated July 13, 2025 Share: 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. View the IronBarcode YouTube Playlist 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 99.99% accuracy. Generate and customize new QR codes with ease! Get started with IronQR now! How to Generate QR Codes in C# 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. First Step: Start for Free Install IronBarcode using the NuGet Package Manager with this simple command: Install-Package BarCode Install via NuGet 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.Linq $vbLabelText $csharpLabel How 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") $vbLabelText $csharpLabel 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") $vbLabelText $csharpLabel 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 image 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 image Imports 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 image $vbLabelText $csharpLabel 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; 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 }) $vbLabelText $csharpLabel 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 If $vbLabelText $csharpLabel Binary 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 If $vbLabelText $csharpLabel For 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) $vbLabelText $csharpLabel 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: GitHub Repository Source Code Download API Documentation Explore the complete feature set in the API reference: QRCodeWriter Class Reference BarcodeReader Class Reference GeneratedBarcode Class 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. Simply pass your content, size, and error correction level to create a QR code in one line of code. What image formats can I export QR codes to? IronBarcode supports exporting QR codes to multiple formats including PNG, JPEG, PDF, and HTML. Use methods like SaveAsPng(), SaveAsJpeg(), SaveAsPdf(), or SaveAsHtmlFile() on your generated QR code. How can I add a company logo to a QR code? Use IronBarcode's CreateQrCodeWithLogo() method, passing a QRCodeLogo object containing your logo image. IronBarcode automatically sizes and positions the logo to maintain QR code readability. What is QR code error correction and which level should I use? Error correction allows QR codes to remain readable when partially damaged. IronBarcode offers four levels: Low (7%), Medium (15%), Quartile (25%), and High (30%). Use Medium for general purposes or High for outdoor/industrial applications. How do I verify if a customized QR code is still readable? Use the Verify() method on your GeneratedBarcode object. This method tests if the QR code can be successfully scanned after customizations like color changes or logo additions. Can I encode binary data like files or encrypted content in QR codes? Yes, IronBarcode's CreateQrCode() method accepts byte arrays, allowing you to encode any binary data including files, encrypted content, or serialized objects into QR codes. How do I read QR codes from images in C#? Use IronBarcode's BarcodeReader.Read() method with the image file path. For better performance, specify BarcodeEncoding.QRCode in the BarcodeReaderOptions. What's the maximum data capacity of a QR code? QR codes created with IronBarcode can store up to 2,953 bytes of binary data, 4,296 alphanumeric characters, or 7,089 numeric digits, depending on the error correction level. How can I change the color of a QR code while keeping it scannable? Use the ChangeBarCodeColor() method on your generated QR code. Always verify readability with Verify() after color changes, as low contrast colors may affect scanning reliability. Is there a specialized library for advanced QR code features? Yes, IronQR is Iron Software's specialized QR code library featuring machine learning-powered reading with 99.99% accuracy and advanced generation capabilities for demanding applications. Jacob Mellor Chat with engineering team now Chief Technology Officer 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.Jacob holds a First-Class Honours Bachelor of Engineering (BEng) in Civil Engineering from the University of Manchester (1998–2001). After opening his first software business in London in 1999 and creating his first .NET components in 2005, he specialized in solving complex problems across the Microsoft ecosystem.His flagship IronPDF & IronSuite .NET libraries have achieved over 30 million NuGet installations globally, with his foundational code continuing to power developer tools used worldwide. With 25 years of commercial experience and 41 years of coding expertise, Jacob remains focused on driving innovation in enterprise-grade C#, Java, and Python PDF technologies while mentoring the next generation of technical leaders. Ready to Get Started? Free NuGet Download Total downloads: 1,731,487 View Licenses