using IronQr;using IronSoftware.Drawing;var reader = new QrReader();IEnumerable<QrResult> results = reader.Read(new QrImageInput("label.png"));if (!results.Any()){Console.WriteLine("No QR code detected or decoding failed."); return;}Console.WriteLine(results.First().Value);
using IronQr;
using IronSoftware.Drawing;
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput("label.png"));
if (!results.Any())
{
Console.WriteLine("No QR code detected or decoding failed.");
return;
}
Console.WriteLine(results.First().Value);
using IronQr;using IronSoftware.Drawing;var reader = new QrReader();IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("damaged-label.png")));// Reed-Solomon decoding is pass/fail — presence in results means valid checksumif (!results.Any()){ // Decoding failed entirely — damage exceeded the error correction capacityConsole.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time."); return;}foreach (QrResult result in results){ // Decoded successfully — validate the content matches expected format if (string.IsNullOrWhiteSpace(result.Value)) {Console.WriteLine("QR decoded but produced an empty value."); continue; }Console.WriteLine($"Valid QR: {result.Value}");}
using IronQr;
using IronSoftware.Drawing;
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("damaged-label.png")));
// Reed-Solomon decoding is pass/fail — presence in results means valid checksum
if (!results.Any())
{
// Decoding failed entirely — damage exceeded the error correction capacity
Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.");
return;
}
foreach (QrResult result in results)
{
// Decoded successfully — validate the content matches expected format
if (string.IsNullOrWhiteSpace(result.Value))
{
Console.WriteLine("QR decoded but produced an empty value.");
continue;
}
Console.WriteLine($"Valid QR: {result.Value}");
}
using IronQr;using IronSoftware.Drawing;using IronQr.Enum;// Read from an image file with ML + classic scan (default)var reader = new QrReader();IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("product-label.png")));foreach (QrResult result in results){ // Inspect the detected QR formatConsole.WriteLine($"Format: {result.QrType}"); // QRCode, MicroQRCode, or RMQRCodeConsole.WriteLine($"Value: {result.Value}"); // Url is non-null only if Value is a valid URI if (result.Url != null) {Console.WriteLine($"URI: {result.Url.AbsoluteUri}"); } // Corner coordinates for positional contextConsole.WriteLine($"Corners: {result.Points.Length} points detected");}// Read from a bitmap with ML-only mode for faster throughputvar bitmap = AnyBitmap.FromFile("camera-capture.jpg");var fastResults = reader.Read(new QrImageInput(bitmap, QrScanMode.OnlyDetectionModel));
using IronQr;
using IronSoftware.Drawing;
using IronQr.Enum;
// Read from an image file with ML + classic scan (default)
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("product-label.png")));
foreach (QrResult result in results)
{
// Inspect the detected QR format
Console.WriteLine($"Format: {result.QrType}"); // QRCode, MicroQRCode, or RMQRCode
Console.WriteLine($"Value: {result.Value}");
// Url is non-null only if Value is a valid URI
if (result.Url != null)
{
Console.WriteLine($"URI: {result.Url.AbsoluteUri}");
}
// Corner coordinates for positional context
Console.WriteLine($"Corners: {result.Points.Length} points detected");
}
// Read from a bitmap with ML-only mode for faster throughput
var bitmap = AnyBitmap.FromFile("camera-capture.jpg");
var fastResults = reader.Read(new QrImageInput(bitmap, QrScanMode.OnlyDetectionModel));
using IronQr;using IronQr.Enum;using IronSoftware.Drawing;using System.Collections.Generic;using System.Linq;public static class QrValidator{ public static List<QrResult> GetValidResults( string imagePath, QrEncoding? expectedFormat = null) { var reader = new QrReader(); IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile(imagePath))); // Guard: no QR codes detected if (!results.Any()) return new List<QrResult>(); return results .Where(r => !string.IsNullOrWhiteSpace(r.Value)) .Where(r => expectedFormat == null || r.QrType == expectedFormat) .ToList(); }}// Usage — only accept standard QR codes with non-empty valuesvar validated = QrValidator.GetValidResults( "shipping-manifest.png", expectedFormat: QrEncoding.QRCode);if (validated.Count == 0){Console.WriteLine("No valid QR codes found for processing."); return;}foreach (var qr in validated){ // Safe for downstream: value is non-empty, format is verifiedSendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri);}
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
using System.Linq;
public static class QrValidator
{
public static List<QrResult> GetValidResults(
string imagePath,
QrEncoding? expectedFormat = null)
{
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile(imagePath)));
// Guard: no QR codes detected
if (!results.Any())
return new List<QrResult>();
return results
.Where(r => !string.IsNullOrWhiteSpace(r.Value))
.Where(r => expectedFormat == null || r.QrType == expectedFormat)
.ToList();
}
}
// Usage — only accept standard QR codes with non-empty values
var validated = QrValidator.GetValidResults(
"shipping-manifest.png",
expectedFormat: QrEncoding.QRCode);
if (validated.Count == 0)
{
Console.WriteLine("No valid QR codes found for processing.");
return;
}
foreach (var qr in validated)
{
// Safe for downstream: value is non-empty, format is verified
SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri);
}
What is the role of the `QrResult` class in IronQR?
The `QrResult` class in IronQR represents decoded results from QR code reading. It provides properties like the decoded value, detected QR type, and optionally, a URI if the value is a valid URL.
How does IronQR handle physical damage to QR codes?
IronQR uses Reed-Solomon error correction to automatically correct minor damages in QR codes during decoding, making it more resilient to physical damage and ensuring data integrity.
Can IronQR validate QR codes asynchronously?
Yes, IronQR supports asynchronous workflows. You can use `ReadAsync` to perform non-blocking QR code reading while applying similar validation patterns on the results.