// Import necessary IronQR and IronDrawing namespacesusing IronSoftware.Drawing; using IronBarcode;public class QRCodeReader{ public static voidMain() { // Load an image from a file path using (var inputImage = Image.FromFile("path/to/your/image/file.webp")) { // Create a QrImageInput object from the image var qrImageInput = new QrImageInput(inputImage); // Decode the 二维码 from the image var result = BarcodeReader.Read(qrImageInput); // Iterate through each detected 二维码 and display its information foreach (var barcodeResult in result.Barcodes) {Console.WriteLine($"QR Code Data: {barcodeResult.Value}"); } } }}
// Import necessary IronQR and IronDrawing namespaces
using IronSoftware.Drawing;
using IronBarcode;
public class QRCodeReader
{
public static void Main()
{
// Load an image from a file path
using (var inputImage = Image.FromFile("path/to/your/image/file.webp"))
{
// Create a QrImageInput object from the image
var qrImageInput = new QrImageInput(inputImage);
// Decode the 二维码 from the image
var result = BarcodeReader.Read(qrImageInput);
// Iterate through each detected 二维码 and display its information
foreach (var barcodeResult in result.Barcodes)
{
Console.WriteLine($"QR Code Data: {barcodeResult.Value}");
}
}
}
}
// Example: Reading 二维码s with enhanced error correctionusing IronBarcode;public class EnhancedQRReader{ public static voidReadPoorQualityImage() { // Configure reader with multiple attempts and error correction var options = new BarcodeReaderOptions {Speed = ReadingSpeed.Detailed, // More thorough scanningExpectMultipleBarcodes = true, // Check for multiple codesExpectBarcodeTypes = BarcodeType.QRCode// Focus on 二维码s only }; using (var inputImage = Image.FromFile("blurry_qr_code.jpg")) { var qrImageInput = new QrImageInput(inputImage); var results = BarcodeReader.Read(qrImageInput, options); foreach (var result in results.Barcodes) {Console.WriteLine($"Decoded: {result.Value}");Console.WriteLine($"Confidence: {result.Confidence}%"); } } }}
// Example: Reading 二维码s with enhanced error correction
using IronBarcode;
public class EnhancedQRReader
{
public static void ReadPoorQualityImage()
{
// Configure reader with multiple attempts and error correction
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Detailed, // More thorough scanning
ExpectMultipleBarcodes = true, // Check for multiple codes
ExpectBarcodeTypes = BarcodeType.QRCode // Focus on 二维码s only
};
using (var inputImage = Image.FromFile("blurry_qr_code.jpg"))
{
var qrImageInput = new QrImageInput(inputImage);
var results = BarcodeReader.Read(qrImageInput, options);
foreach (var result in results.Barcodes)
{
Console.WriteLine($"Decoded: {result.Value}");
Console.WriteLine($"Confidence: {result.Confidence}%");
}
}
}
}
using System;using System.Collections.Generic;using System.Linq;using IronQr;using System.Drawing;// Import imagevar inputImage = Image.FromFile("sample.jpg");// Load the asset into QrImageInputQrImageInput imageInput = new QrImageInput(inputImage);// Create a QR Reader objectQrReader reader = new QrReader();// Read the Input an get all embedded QR CodesIEnumerable<QrResult> results = reader.Read(imageInput);// Display the value of the first QR code foundConsole.WriteLine($"QR code value is {results.First().Value}");
using System;
using System.Collections.Generic;
using System.Linq;
using IronQr;
using System.Drawing;
// Import image
var inputImage = Image.FromFile("sample.jpg");
// Load the asset into QrImageInput
QrImageInput imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
QrReader reader = new QrReader();
// Read the Input an get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);
// Display the value of the first QR code found
Console.WriteLine($"QR code value is {results.First().Value}");
ImportsSystemImportsSystem.Collections.GenericImportsSystem.LinqImportsIronQrImportsSystem.Drawing' Import imageDim inputImage AsImage = Image.FromFile("sample.jpg")' Load the asset into QrImageInputDim imageInput As New QrImageInput(inputImage)' Create a QR Reader objectDim reader As New QrReader()' Read the Input and get all embedded QR CodesDim results AsIEnumerable(OfQrResult) = reader.Read(imageInput)' Display the value of the first QR code foundConsole.WriteLine($"QR code value is {results.First().Value}")
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports IronQr
Imports System.Drawing
' Import image
Dim inputImage As Image = Image.FromFile("sample.jpg")
' Load the asset into QrImageInput
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read the Input and get all embedded QR Codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Display the value of the first QR code found
Console.WriteLine($"QR code value is {results.First().Value}")
using System;using System.Collections.Generic;using IronQr;using System.Drawing;using System.Linq;// Import an image containing a QR codevar inputImage = Image.FromFile("urlQr.png");// Load the asset into a QrImageInput objectvar imageInput = new QrImageInput(inputImage);// Create a QR Reader objectvar reader = new QrReader();// Read the input and get all embedded QR codesIEnumerable<QrResult> results = reader.Read(imageInput);// [TL, TR, BL, BR]string[] labels = { "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right" };var points = results.First().Points;for (int i = 0; i < points.Length; i++){Console.WriteLine($"{labels[i]}: {points[i].X}, {points[i].Y}");}
using System;
using System.Collections.Generic;
using IronQr;
using System.Drawing;
using System.Linq;
// Import an image containing a QR code
var inputImage = Image.FromFile("urlQr.png");
// Load the asset into a QrImageInput object
var imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
var reader = new QrReader();
// Read the input and get all embedded QR codes
IEnumerable<QrResult> results = reader.Read(imageInput);
// [TL, TR, BL, BR]
string[] labels = { "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right" };
var points = results.First().Points;
for (int i = 0; i < points.Length; i++)
{
Console.WriteLine($"{labels[i]}: {points[i].X}, {points[i].Y}");
}
ImportsSystemImportsSystem.Collections.GenericImportsIronQrImportsSystem.DrawingImportsSystem.Linq' Import an image containing a QR codeDim inputImage AsImage = Image.FromFile("urlQr.png")' Load the asset into a QrImageInput objectDim imageInput As New QrImageInput(inputImage)' Create a QR Reader objectDim reader As New QrReader()' Read the input and get all embedded QR codesDim results AsIEnumerable(OfQrResult) = reader.Read(imageInput)' [TL, TR, BL, BR]Dim labels AsString() = { "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right" }Dim points = results.First().PointsFor i AsInteger = 0 To points.Length - 1Console.WriteLine($"{labels(i)}: {points(i).X}, {points(i).Y}")Next
Imports System
Imports System.Collections.Generic
Imports IronQr
Imports System.Drawing
Imports System.Linq
' Import an image containing a QR code
Dim inputImage As Image = Image.FromFile("urlQr.png")
' Load the asset into a QrImageInput object
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read the input and get all embedded QR codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' [TL, TR, BL, BR]
Dim labels As String() = { "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right" }
Dim points = results.First().Points
For i As Integer = 0 To points.Length - 1
Console.WriteLine($"{labels(i)}: {points(i).X}, {points(i).Y}")
Next
输入二维码
输出
请注意,系统已将每个二维码角点的精确空间坐标记录到控制台。
支持的二维码类型
创建和读取多种类型的二维码均受支持。 IronQR 提供对各种 QR 代码格式的全面支持,以满足不同的应用需求。 在我们的文档中了解更多有关 支持的 QR 格式的信息。 以下是支持的二维码类型:
IronQR 支持从多种图像格式读取 QR 码,包括 JPEG、PNG、GIF、TIFF、BMP、WBMP、WebP、ICO、WMF 和 RawFormat。这种全面的格式支持由 IronDrawing 提供,让您无需进行格式转换即可处理各种来源的二维码。
如何在 C# 中从图像文件读取 QR 码?
要使用 IronQR 读取 QR 代码,首先要使用 Image.FromFile() 加载图像,从加载的图像中创建 QrImageInput 对象,然后使用 BarcodeReader.Read() 解码 QR 数据。该方法会返回结果,您可以遍历这些结果来访问每个检测到的 QR 代码信息。
什么技术可以在不同媒体类型中准确读取 QR 代码?
IronQR 使用先进的机器学习模型来确保不同媒体类型和图像格式的 QR 码解码准确无误。这种人工智能驱动的方法有助于在具有挑战性的图像条件下保持高准确性。
我能从一张图片中读取多个 QR 代码吗?
是的,IronQR 可以从一张图片中检测并读取多个 QR 代码。BarcodeReader.Read 方法会返回一个结果集合,允许您使用foreach 循环遍历每个检测到的 QR 代码,以访问单个 QR 代码数据。
IronQR 读取的二维码中可以存储哪些类型的数据?
IronQR 可以解码二维码中存储的各种类型的数据,包括纯文本、URL、联系方式和其他形式的结构化数据。解码后的信息可通过每个 BarcodeResult 对象的 Value 属性进行访问。
What types of QR codes can IronQR read?
IronQR can read various types of QR codes, including Standard QR Code, Micro QR Code, and RMQR Code, supporting different use cases and data capacities for applications requiring compact or rectangular formats.
When should I choose Micro or RMQR codes?
Choose Micro QR codes for small surfaces like circuit boards or medical devices and RMQR codes for rectangular labels like narrow shipping labels or marketing materials that require fitting into elongated spaces.
How does IronQR locate a QR code within an image?
IronQR uses a standard coordinate system to pinpoint where a QR code is located within an image. It retrieves and prints the exact spatial coordinates of the QR code's corners using the Points[] array.