How To Set Error Correction in C#
Error correction in C# barcodes is set using the QrErrorCorrectionLevel parameter in IronBarcode's QRCodeWriter.CreateQrCode method, supporting four levels (L, M, Q, H) that can recover 7-30% of damaged data, with higher levels creating more complex QR codes.
Error Correction in barcodes refers to the ability to maintain barcode readability despite visual defects or encoding errors. These damages can arise due to factors such as printing imperfections, smudges, scratches, or variations in scanning conditions. Error correction is a major factor in determining which type of barcode encoding is suitable, especially when working with QR codes in C#.
In general, 2D barcodes have a higher tolerance to defects compared to 1D barcodes due to the following factors:
- Data Capacity: 2D barcodes store more data than 1D barcodes, encoding both horizontally and vertically. Learn more about supported barcode formats.
- Redundancy: 2D barcodes have multiple layers of data encoding, allowing information extraction from any remaining intact sections even when part of the barcode is damaged.
- Compactness: 2D barcodes are suitable for limited spaces due to their compact shape.
- Flexibility: 2D barcodes can be scanned from various angles and orientations.
Error correction becomes particularly important when dealing with imperfect barcodes and image correction scenarios where scanning conditions are less than ideal.
Quickstart: Use Error Correction Level in QR Code CreationThis short example shows how to generate a QR code with IronBarcode, setting the error correction level to Medium. Developers can use the CreateQrCode method with content, size, and error correction level.
-
1Install IronBarcode with NuGet Package Manager
-
2Copy and run this code snippet.
var qr = IronBarCode.QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, IronBarCode.QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("qr.png");C# -
3Deploy to test on your live environment
Start using IronBarcode in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library to adjust error correction on barcodes
- Use the QRCodeWriter class to generate a QR code
- Modify the QrErrorCorrection parameter to adjust the error correction level
- Compare the QR codes generated visually at four different error correction levels
- Examine the output QR codes
How Do I Adjust Error Correction in QR Codes?
Currently, IronBarcode supports setting error correction in QR Codes, Micro QRs, and rMQRs as part of its comprehensive barcode generation features. It supports all four pre-set error correction levels specified by QR code standards. The error correction level is adjusted via the QrErrorCorrectionLevel parameter in the QRCodeWriter.CreateQrCode method. The four levels of error correction are:
- Highest: Level H. Can recover up to 30% of data.
- High: Level Q. Can recover up to 25% of data.
- Medium: Level M. Can recover up to 15% of data.
- Low: Level L. Can recover up to 7% of data.
Higher error correction levels result in more complex QR code images, requiring a balance between visual clarity and error correction when generating QR codes. The code sample below demonstrates setting error correction:
// Import the necessary namespace for barcode generation
using IronBarCode;
// Create a QR code with the specified URL, size, and error correction level
GeneratedBarcode mediumCorrection = QRCodeWriter.CreateQrCode(
"https://ironsoftware.com/csharp/barcode/", // URL to be encoded in the QR code
500, // Size of the QR code (500x500 pixels)
QRCodeWriter.QrErrorCorrectionLevel.Medium // Error correction level to handle distortions
);
// Save the generated QR code image as a PNG file with the specified filename
mediumCorrection.SaveAsPng("mediumCorrection.png");' Import the necessary namespace for barcode generation
Imports IronBarCode
' Create a QR code with the specified URL, size, and error correction level
Private mediumCorrection As GeneratedBarcode = QRCodeWriter.CreateQrCode("https://ironsoftware.com/csharp/barcode/", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium)
' Save the generated QR code image as a PNG file with the specified filename
mediumCorrection.SaveAsPng("mediumCorrection.png")Which Error Correction Level Should I Choose?
The choice of error correction level depends on your specific use case and environment. For applications where QR codes might be exposed to physical damage, dirt, or partial obscuration, higher error correction levels (Q or H) are recommended. These levels provide better fault tolerance at the cost of increased QR code complexity and size.
For clean, controlled environments like digital displays or high-quality printing, lower error correction levels (L or M) may suffice. These produce simpler, less dense QR codes that are easier to scan at smaller sizes. Consider these factors:
- Physical Environment: Outdoor or industrial settings benefit from higher error correction
- Print Quality: Lower quality printing requires higher error correction
- Size Constraints: Limited space may require lower error correction for readability
- Scanning Distance: Longer scanning distances work better with simpler QR codes
Here's an example showing how to generate QR codes with different error correction levels for comparison:
using IronBarCode;
using System.Drawing;
// Generate QR codes with all four error correction levels
var content = "https://ironsoftware.com/csharp/barcode/";
int size = 500;
// Create QR codes with different error correction levels
var lowCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Low);
var mediumCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Medium);
var highCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.High);
var highestCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Highest);
// Save each with descriptive filenames
lowCorrection.SaveAsPng("qr_low_correction.png");
mediumCorrection.SaveAsPng("qr_medium_correction.png");
highCorrection.SaveAsPng("qr_high_correction.png");
highestCorrection.SaveAsPng("qr_highest_correction.png");Imports IronBarCode
Imports System.Drawing
' Generate QR codes with all four error correction levels
Dim content As String = "https://ironsoftware.com/csharp/barcode/"
Dim size As Integer = 500
' Create QR codes with different error correction levels
Dim lowCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Low)
Dim mediumCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Medium)
Dim highCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.High)
Dim highestCorrection = QRCodeWriter.CreateQrCode(content, size, QRCodeWriter.QrErrorCorrectionLevel.Highest)
' Save each with descriptive filenames
lowCorrection.SaveAsPng("qr_low_correction.png")
mediumCorrection.SaveAsPng("qr_medium_correction.png")
highCorrection.SaveAsPng("qr_high_correction.png")
highestCorrection.SaveAsPng("qr_highest_correction.png")What Parameters Control Error Correction?
The primary parameter controlling error correction in IronBarcode is the QrErrorCorrectionLevel enumeration. This parameter is passed to the CreateQrCode method and determines how much redundant data is embedded in the QR code. When creating custom QR codes, you can combine error correction settings with other styling options:
using IronBarCode;
// Create a styled QR code with high error correction
var styledQr = QRCodeWriter.CreateQrCode("Important Data", 500, QRCodeWriter.QrErrorCorrectionLevel.High);
// Apply custom styling
styledQr.ChangeBarCodeColor(System.Drawing.Color.DarkBlue)
.SetMargins(10)
.AddAnnotationTextAboveBarcode("Scan for Details");
// Export with various options
styledQr.SaveAsPng("styled_high_correction.png");
styledQr.SaveAsJpeg("styled_high_correction.jpg");
styledQr.SaveAsPdf("styled_high_correction.pdf");Imports IronBarCode
Imports System.Drawing
' Create a styled QR code with high error correction
Dim styledQr = QRCodeWriter.CreateQrCode("Important Data", 500, QRCodeWriter.QrErrorCorrectionLevel.High)
' Apply custom styling
styledQr.ChangeBarCodeColor(Color.DarkBlue) _
.SetMargins(10) _
.AddAnnotationTextAboveBarcode("Scan for Details")
' Export with various options
styledQr.SaveAsPng("styled_high_correction.png")
styledQr.SaveAsJpeg("styled_high_correction.jpg")
styledQr.SaveAsPdf("styled_high_correction.pdf")Why Does Error Correction Affect QR Code Complexity?
Error correction works by adding redundant data to the QR code using Reed-Solomon error correction algorithms. This redundancy allows the QR code reader to reconstruct missing or damaged portions of the data. The more error correction added, the more modules (black and white squares) are needed to encode the same information, resulting in a denser, more complex pattern.
This complexity has practical implications for barcode reading settings and scanning performance. Higher error correction levels may require adjustments to reader settings for optimal performance.
What Are the Different Error Correction Levels?
Below is a sample set of QR Code images, each representing the same value but with varying levels of error correction. As observed, higher error correction levels lead to more complex QR code images, offering greater fault tolerance.

Highest Error Correction

High Error Correction

Medium Error Correction

Low Error Correction
When Should I Use Higher Error Correction?
Higher error correction levels are recommended in several scenarios:
- Industrial Applications: When QR codes are used on products or equipment exposed to harsh conditions
- Outdoor Signage: For QR codes displayed outdoors subject to weather damage
- Long-term Storage: Documents or products that need to remain scannable for years
- Marketing Materials: When incorporating logos or designs that partially obscure the QR code
For advanced scenarios involving reading multiple barcodes or processing damaged images, higher error correction provides additional reliability.
How Does Error Correction Impact QR Code Size?
Error correction directly impacts the physical size and data capacity of QR codes. Higher error correction levels require more modules to encode the same amount of data, which can result in:
- Larger QR codes for the same data content
- Reduced maximum data capacity at a given QR code size
- More complex patterns that may be harder to scan at small sizes
- Increased processing time for both generation and scanning
What Are the Visual Differences Between Correction Levels?
The visual differences between error correction levels become apparent when comparing QR codes encoding the same data. Lower correction levels produce simpler patterns with fewer modules, while higher levels create denser, more intricate patterns. These differences affect not only appearance but also practical considerations for printing and display.
For more advanced barcode generation techniques, explore our comprehensive documentation and learn about integrating error correction with other barcode features for optimal results in your .NET applications.
Frequently Asked Questions
What is error correction in QR codes?
Error correction in QR codes refers to the ability to maintain readability despite visual defects or encoding errors. IronBarcode allows you to set error correction using the `QrErrorCorrectionLevel` parameter in the `QRCodeWriter.CreateQrCode` method, supporting levels L, M, Q, and H.
How can I set the error correction level for a QR code in C#?
In IronBarcode, you can set the error correction level by using the `QrErrorCorrectionLevel` parameter in the `CreateQrCode` method. This allows you to adjust the level of data recovery handled by the barcode.
Why is error correction important for QR codes?
Error correction ensures that QR codes remain scannable even when they are damaged or exposed to imperfect conditions such as printing defects or smudges. IronBarcode supports multiple error correction levels to maintain data integrity.
How do different error correction levels affect QR codes?
Higher error correction levels in QR codes result in more complex patterns and a larger number of black and white modules. They offer greater fault tolerance but may increase the physical size and complexity of the QR code, which IronBarcode handles through its versatile library features.
What are the four error correction levels supported by IronBarcode?
IronBarcode supports four levels of error correction: L (low, 7% data recovery), M (medium, 15% data recovery), Q (high, 25% data recovery), and H (highest, 30% data recovery). Each level balances between complexity and fault tolerance.
In what situations should higher QR code error correction be used?
Higher error correction levels are ideal in conditions where QR codes might experience physical damage, such as outdoor environments, industrial applications, or use on marketing materials with overlays.
Does IronBarcode support custom styling with error correction settings?
Yes, IronBarcode allows you to create styled QR codes, combining custom design elements with error correction settings for more functional and appealing barcodes.
Can I compare QR codes with different error correction levels using IronBarcode?
Absolutely, IronBarcode allows you to generate and visually compare QR codes with different error correction levels, enabling developers to balance between size, complexity, and scannability.
What impact does error correction have on QR code scanning performance?
QR code error correction influences scanning performance, as higher levels may necessitate adjustments to scanner settings due to their increased complexity and density of information, a feature managed efficiently by IronBarcode.
How does IronBarcode enhance QR code generation for .NET developers?
IronBarcode offers .NET developers a powerful tool to generate QR codes with adjustable error correction levels, optimal reader settings, and custom styling options, all critical for ensuring both aesthetic appeal and functional reliability.
