QRCodeImageReader Class
Provides methods to read the QR codes of an image: standard QR codes, Micro QR codes and rMQR codes.
public static class QRCodeImageReaderMethods
| Name | Description |
|---|---|
| ReadQRCodes(Image, QRCodeReadingOptions?, CancellationToken) | Reads the QR codes of an image. |
ReadQRCodes(Image, QRCodeReadingOptions?, CancellationToken)
QRCodeImageReader.csReads the QR codes of an image.
public static IReadOnlyList<QRCodeImageResult> ReadQRCodes(this Image image, QRCodeReadingOptions? options = null, CancellationToken cancellationToken = default)Parameters
imageImage- The image. For an animated image, its first frame is read.
optionsQRCodeReadingOptions?- The reading options, or
nullfor the defaults. cancellationTokenCancellationToken- A token to cancel the reading.
Returns
IReadOnlyList<QRCodeImageResult> The QR codes found, each once; empty when there is none.
Exceptions
ArgumentNullExceptionimageisnull.OperationCanceledExceptioncancellationTokenwas canceled.
Remarks
The reader is made for clean images: generated, printed or scanned symbols, photographed straight on. It finds the finder patterns of the symbols, which can be rotated, scaled, slightly blurred or in mild perspective, samples their modules and decodes them with QRCodeDecoder. A transparent background reads as white.
A symbol needs its quiet zone and modules of at least 2 pixels. The pixels are classified as dark or light with the Otsu threshold of the image, then with a local threshold (Sauvola) when no symbol is found.
Example
using var image = QRCode.Create("https://www.meziantou.net").ToImage(); // or Image.Load("photo.png")
var results = image.ReadQRCodes();
var result = Assert.Single(results);
Assert.Equal("https://www.meziantou.net", result.Text);
// The corners of the symbol in the image: top-left, top-right, bottom-right, bottom-left
var topLeft = result.Corners[0];
Assert.True(topLeft.DistanceTo(new PointD(40, 40)) < 1); // after the quiet zone of 4 modules of 10 pixels