如何從圖像中讀取 QR Code

查克尼思·賓
查克尼思·賓
2024年10月13日
已更新 2024年10月13日
分享:
This article was translated from English: Does it need improvement?
Translated
View the article in English

閱讀 QR 碼是指掃描並解碼儲存在 QR 碼中的信息的過程。 這通常是通過與能夠解析 QR 碼數據的軟體配合使用的相機或掃描器來完成的。 QR碼中的資訊可以是文字、網址、聯繫資料或其他形式的數據。

立即在您的專案中使用IronQR,並享受免費試用。

第一步:
green arrow pointer

從圖像讀取 QR 碼

IronQR的一個突出功能是其內建的能力,可以無縫地從各種圖像格式中讀取QR碼。 這包括:

* 聯合影像專家小組 (JPEG)

* 可攜式網絡圖形 (PNG)

* 圖形交換格式 (GIF)

* 標記圖像文件格式 (TIFF)

* 點陣圖影像檔 (BMP)

* WBMP

* WebP

* 图标 (ico)

* WMF

* 原始格式 (raw)

此功能由開源庫IronDrawing啟用。 現在讓我們來探索如何使用 IronQR 從下方圖片讀取 QR 碼。

QR碼
:path=/static-assets/qr/content-code-examples/how-to/read-qr-code-image.cs
using IronQr;
using IronSoftware.Drawing;
using System.Collections.Generic;
using System;

// Open the asset to read a QR Code from
var inputBmp = AnyBitmap.FromFile("IMAGE_TO_READ.png");

// Load the asset into QrImageInput
QrImageInput imageInput = new QrImageInput(inputBmp);

// Create a QR Reader object
QrReader reader = new QrReader();

// Read the Input an get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);

foreach (var result in results)
{
    Console.WriteLine(result.Value);
}
Imports IronQr
Imports IronSoftware.Drawing
Imports System.Collections.Generic
Imports System

' Open the asset to read a QR Code from
Private inputBmp = AnyBitmap.FromFile("IMAGE_TO_READ.png")

' Load the asset into QrImageInput
Private imageInput As New QrImageInput(inputBmp)

' Create a QR Reader object
Private reader As New QrReader()

' Read the Input an get all embedded QR Codes
Private results As IEnumerable(Of QrResult) = reader.Read(imageInput)

For Each result In results
	Console.WriteLine(result.Value)
Next result
$vbLabelText   $csharpLabel

想知道樣本圖像中的 QR 碼值嗎?試試使用程式碼片段吧!


支持的 QR Code 類型

支援多種類型的QR碼,用於創建和讀取。 以下是支持的 QR 代碼類型:

  • QRCode:這是目前最常用的標準 QR 碼。 它可以存儲大量數據(最多可達 7,089 個數字字符或 4,296 個字母數字字符),使其適用於廣泛的應用程序,從網站網址到聯繫信息。

    QR碼
  • MicroQRCode:微型 QR 碼是標準 QR 碼的縮小版,專為空間有限的情況設計。 它能存儲的數據比標準 QR 碼少(最多 35 個數字字符或 21 個字母數字字符),但其小巧的尺寸使其成為在標準 QR 碼過大時的理想選擇,例如在小型包裝或微小的打印標籤上。

    QR碼
  • RMQRCode:RMQR Code(矩形微型 QR 碼)是 QR 碼的另一種緊湊版本,但形狀為矩形而非正方形。 此版本允許其長寬比具有靈活性,這對於可用矩形空間的應用程式可能很有用。 它可以存儲類似於微型 QR 碼的數據,但專為可用空間不規則的特定使用情況而設計。
    QR碼
查克尼思·賓
軟體工程師
Chaknith 致力於 IronXL 和 IronBarcode。他在 C# 和 .NET 方面擁有豐富的專業知識,協助改進軟體並支持客戶。他從用戶互動中獲得的洞察力有助於提高產品、文檔和整體體驗。