How To Set Error Correction
What is Error Correction?
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.
In general, 2D barcodes have a higher tolerance to defects compared to 1D barcodes due to the following factors:
- Data Capacity: 2D barcodes can store significantly more data than 1D barcodes as they encode data both horizontally and vertically, accommodating alphanumerics, binary data, images, and more.
- 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.
How to Set Error Correction
- 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
Start using IronBarcode in your project today with a free trial.
Adjust Error Correction in QR Codes Example
Currently, IronBarcode supports setting error correction in QR Codes, Micro QRs, and rMQRs. It supports all four pre-set error correction levels specified by QR code standards. The error correction level is adjusted via the QrErrorCorrection 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")
Error Correction Comparison
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
Frequently Asked Questions
What is error correction in barcodes and why is it important?
Error correction in barcodes is the capability to maintain readability despite visual defects or encoding errors, such as smudges or scratches. This feature is crucial for ensuring data accuracy and reliability in barcode applications.
How do 2D barcodes differ from 1D barcodes in terms of error correction?
2D barcodes differ from 1D barcodes due to their higher data capacity, redundancy, compactness, and flexibility. This allows 2D barcodes to be more resilient to damage and more easily scanned from various angles, enhancing their error correction capabilities.
How can I set error correction levels in QR codes using C#?
To set error correction levels in QR codes using C#, you can use the IronBarcode library. Download the library, use the QRCodeWriter
class, and adjust the QrErrorCorrection
parameter to set the desired error correction level.
What are the available error correction levels for QR codes?
QR codes support four error correction levels: Highest (Level H, 30% data recovery), High (Level Q, 25% data recovery), Medium (Level M, 15% data recovery), and Low (Level L, 7% data recovery). These levels determine how much data can be recovered if the QR code is damaged.
How does modifying error correction levels affect the appearance of QR codes?
Modifying error correction levels affects the complexity of QR codes. Higher error correction levels result in more intricate images, balancing between visual clarity and data recovery capability.
What method is used to create a QR code with specific error correction in C#?
In C#, the QRCodeWriter.CreateQrCode
method is used to generate a QR code with a specified error correction level by adjusting the QrErrorCorrection
parameter.
Can error correction be applied to barcode types other than QR codes using this library?
Yes, the IronBarcode library supports error correction in other barcode types such as Micro QR and rMQR, in addition to QR codes.
What impact does error correction have on the data capacity of barcodes?
Higher error correction levels decrease the data capacity of barcodes because more space is used to store error correction data, reducing the amount of space available for actual data.