QRCodeDecoder Class
Reads the data of QR codes, Micro QR codes and rMQR codes from their modules: the format information, the error correction, and the segments of the data.
public static class QRCodeDecoderRemarks
The decoder works on modules, not on pixels. To read the QR codes of an image, use the ReadQRCodes methods of the Meziantou.Framework.Imaging.Barcodes package, which locate the symbols and sample their modules.
Methods
| Name | Description |
|---|---|
| Decode(QRCode) | Reads the data of a QR code. |
| Decode(bool[,]) | Reads the data of a QR code from its modules. |
| MergeStructuredAppend(IEnumerable<QRCodeDecodeResult>) | Puts the data of a structured append sequence back together. |
| TryDecode(bool[,], QRCodeDecodeResult?) | Tries to read the data of a QR code from its modules. |
Decode overloads
Decode(QRCode)
QRCodeDecoder.csReads the data of a QR code.
public static QRCodeDecodeResult Decode(QRCode qrCode)Parameters
qrCodeQRCode- The QR code.
Returns
QRCodeDecodeResult The content of the QR code.
Exceptions
ArgumentNullExceptionqrCodeisnull.
Example
var qrCode = QRCode.Create("https://www.meziantou.net", ErrorCorrectionLevel.M);
var result = QRCodeDecoder.Decode(qrCode);
Assert.Equal("https://www.meziantou.net", result.Text);
Assert.Equal((QRCodeType.Standard, 2, ErrorCorrectionLevel.M), (result.Type, result.Version, result.ErrorCorrectionLevel));Decode(bool[,])
QRCodeDecoder.csReads the data of a QR code from its modules.
public static QRCodeDecodeResult Decode(bool[,] modules)Parameters
modulesbool[,]- The modules,
truefor dark, indexed by row then column, without quiet zone. The size of the matrix gives the type of the symbol: a square of 21 to 177 modules is a standard QR code, a square of 11 to 17 modules a Micro QR code, and a rectangle an rMQR code.
Returns
QRCodeDecodeResult The content of the QR code.
Exceptions
ArgumentNullExceptionmodulesisnull.FormatException- The modules are not a QR code, or have more errors than the error correction can fix.
MergeStructuredAppend(IEnumerable<QRCodeDecodeResult>)
QRCodeDecoder.csPuts the data of a structured append sequence back together.
public static string MergeStructuredAppend(IEnumerable<QRCodeDecodeResult> results)Parameters
resultsIEnumerable<QRCodeDecodeResult>- The decoded symbols of the sequence, in any order.
Returns
string The text of the sequence.
Exceptions
ArgumentNullExceptionresultsisnullor containsnull.ArgumentException- A symbol is not part of a structured append sequence, the symbols belong to different sequences, a symbol is missing or repeated, or the parity of the data does not match.
Example
var text = "Structured append splits this text across several QR codes, and the reader puts it back together.";
var symbols = QRCode.CreateStructuredAppend(text, ErrorCorrectionLevel.M, new QRCodeOptions { MaximumVersion = 2 });
// The symbols can be read in any order
var results = symbols.Reverse().Select(QRCodeDecoder.Decode).ToList();
Assert.Equal(text, QRCodeDecoder.MergeStructuredAppend(results));TryDecode(bool[,], QRCodeDecodeResult?)
QRCodeDecoder.csTries to read the data of a QR code from its modules.
public static bool TryDecode(bool[,] modules, out QRCodeDecodeResult? result)Parameters
modulesbool[,]- The modules,
truefor dark, indexed by row then column, without quiet zone. resultQRCodeDecodeResult?- When this method returns
true, the content of the QR code.
Returns
bool true if the modules are a QR code that could be read; otherwise, false.
Exceptions
ArgumentNullExceptionmodulesisnull.