WPF QR 碼掃描器
using IronQr;
using IronSoftware.Drawing;
using Microsoft.Win32;

// Open a file dialog to select a QR code image
var dialog = new OpenFileDialog
{
    Title = "Select a QR code image",
    Filter = "Image Files|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tiff"
};

if (dialog.ShowDialog() == true)
{
    // Load the selected image into IronQR
    var inputBmp = AnyBitmap.FromFile(dialog.FileName);
    QrImageInput imageInput = new QrImageInput(inputBmp);

    // Create a QR Reader object and read the image
    QrReader reader = new QrReader();
    IEnumerable<QrResult> results = reader.Read(imageInput);

    // Display the first result
    ResultLabel.Text = results.FirstOrDefault()?.Value ?? "No QR code found.";
}
NuGet 下載
PM > Install-Package IronQR
WPF QR 碼掃描器

WPF QR 碼掃描器

使用 IronQR 在 WPF 桌面應用程式中掃描 QR Code。透過原生的 OpenFileDialog 開啟影像檔案,使用 AnyBitmap.FromFile 載入,再以 QrReader.Read 解碼。無需 JavaScript 或瀏覽器。

在 WPF 中掃描 QR Code 的 5 步驟指南

  • using IronQr;
  • using IronSoftware.Drawing;
  • var dialog = new OpenFileDialog { Filter = "圖像文件|.png;.jpg;.jpeg;.bmp" };
  • var inputBmp = AnyBitmap.FromFile(dialog.FileName);
  • var results = reader.Read(imageInput/);

程式碼說明

OpenFileDialog 提供 Windows 原生的檔案選取功能,並可篩選常見的影像類型。AnyBitmap.FromFile 會將選取的檔案載入為點陣圖,不受格式限制。QrImageInput 會封裝該點陣圖,讓 IronQR 能夠處理;QrReader.Read 則傳回 IEnumerable<QrResult>,其中每個項目對應影像中偵測到的一個 QR Code。FirstOrDefault 會安全地取得第一個結果,避免影像中沒有 QR Code 時應用程式當機。

了解如何使用 IronQR 建立 WPF QR Code 掃描器。

準備好開始了嗎?

NuGet 下載次數 83,364版本:2026.11剛剛發布