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 Creation
This 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.
Get started making PDFs with NuGet now:
Install IronBarcode with NuGet Package Manager
Copy and run this code snippet.
var qr = IronBarCode.QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, IronBarCode.QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("qr.png");Deploy to test on your live environment
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:
:path=/static-assets/barcode/content-code-examples/how-to/set-error-correction.cs// 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");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");IRON VB CONVERTER ERROR developers@ironsoftware.comWhat 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");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");IRON VB CONVERTER ERROR developers@ironsoftware.comWhy 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 barcode technology?
Error correction in barcodes refers to the ability to maintain barcode readability despite visual defects or encoding errors. IronBarcode implements error correction through the QrErrorCorrectionLevel parameter, which allows recovery of 7-30% of damaged data depending on the level chosen.
How do I set error correction levels when creating QR codes in C#?
You can set error correction levels using IronBarcode's QRCodeWriter.CreateQrCode method by specifying the QrErrorCorrectionLevel parameter. The method accepts content, size, and one of four error correction levels (L, M, Q, H).
What are the four error correction levels available for QR codes?
IronBarcode supports four pre-set error correction levels for QR codes: L (Low - 7% recovery), M (Medium - 15% recovery), Q (Quartile - 25% recovery), and H (High - 30% recovery). Higher levels create more complex QR codes but offer better damage resistance.
Which barcode types support error correction settings?
Currently, IronBarcode supports setting error correction levels for QR Codes, Micro QRs, and rMQRs. These 2D barcode formats offer superior error correction capabilities compared to traditional 1D barcodes.
Why do 2D barcodes have better error correction than 1D barcodes?
2D barcodes supported by IronBarcode have better error correction due to higher data capacity (encoding both horizontally and vertically), built-in redundancy allowing data extraction from intact sections, compact shape suitable for limited spaces, and flexibility for scanning from various angles.
When should I use higher error correction levels?
Use higher error correction levels with IronBarcode when dealing with imperfect printing conditions, potential physical damage (scratches, smudges), challenging scanning environments, or when long-term durability is required. Higher levels provide more reliable scanning but increase QR code complexity.






