IRONSOFTWAREHOME

How To Set Error Correction in C#

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Updated: August 2, 2026

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.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    var qr = IronBarCode.QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, IronBarCode.QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("qr.png");
    C#
  3. 3Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer

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");

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");

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");

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.

QR code with highest error correction level showing dense pattern of black and white squares
QR code demonstrating high error correction level with dense data patterns and robust finder patterns
QR code with medium error correction level showing clear data pattern and finder squares
QR code with low error correction level showing standard black and white matrix pattern

When Should I Use Higher Error Correction?

Higher error correction levels are recommended in several scenarios:

  1. Industrial Applications: When QR codes are used on products or equipment exposed to harsh conditions
  2. Outdoor Signage: For QR codes displayed outdoors subject to weather damage
  3. Long-term Storage: Documents or products that need to remain scannable for years
  4. 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.

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required