How to Build a QR Code Scanner in WPF

Windows Presentation Foundation (WPF) is a .NET framework for building Windows desktop applications with XAML-defined UIs. IronQR integrates directly into WPF, enabling QR code scanning from user-selected image files with just a few lines of C#.

In this guide, we'll build a WPF application that opens a file dialog, loads a selected image, and decodes any embedded QR code using IronQR. The approach supports PNG, JPEG, BMP, GIF, TIFF, and other common image formats.

Prerequisites

  1. Visual Studio 2022 with the .NET desktop development workload installed
  2. A WPF project targeting .NET 8 or later

Install IronQR

Install the IronQR library using the NuGet Package Manager Console in Visual Studio. Navigate to Tools > NuGet Package Manager > Package Manager Console and run:

Install-Package IronQR

Alternatively, search for IronQR on NuGet and install the latest version.

WPF Window Layout

The scanner UI uses a Button to trigger the file dialog and a TextBlock to display the decoded result. Add the following markup to MainWindow.xaml:

<StackPanel Margin="28" VerticalAlignment="Center">

    <TextBlock Text="WPF QR Code Scanner" FontSize="20" FontWeight="Bold" Margin="0,0,0,16"/>

    <Button x:Name="ScanButton"
            Content="Select Image and Scan QR Code"
            Click="OnScanButtonClicked"
            Padding="12,8"
            Margin="0,0,0,16"
            HorizontalAlignment="Left"/>

    <TextBlock x:Name="ResultLabel"
               Text="Select an image to scan."
               TextWrapping="Wrap"
               FontSize="14"/>

</StackPanel>
<StackPanel Margin="28" VerticalAlignment="Center">

    <TextBlock Text="WPF QR Code Scanner" FontSize="20" FontWeight="Bold" Margin="0,0,0,16"/>

    <Button x:Name="ScanButton"
            Content="Select Image and Scan QR Code"
            Click="OnScanButtonClicked"
            Padding="12,8"
            Margin="0,0,0,16"
            HorizontalAlignment="Left"/>

    <TextBlock x:Name="ResultLabel"
               Text="Select an image to scan."
               TextWrapping="Wrap"
               FontSize="14"/>

</StackPanel>
XML

Sample Input

Use the QR code below as a test image. Save it to your device, select it through the file dialog, and click Select Image and Scan QR Code. The decoded value should display as https://ironsoftware.com.**

Sample QR code encoding https://ironsoftware.com for testing the WPF QR scanner

Sample QR code — encodes https://ironsoftware.com

QR Code Scanning with IronQR

When the button is clicked, OnScanButtonClicked opens a file dialog to select an image. The selected file is loaded into an AnyBitmap, passed to QrReader.Read, and the first decoded value is written to ResultLabel.

Add the following OnScanButtonClicked method to MainWindow.xaml.cs:

:path=/static-assets/qr/content-code-examples/get-started/wpf-qr-code-scanner.cs
using IronQr;
using IronSoftware.Drawing;
using Microsoft.Win32;
using System.Windows;

private void OnScanButtonClicked(object sender, RoutedEventArgs e)
{
    // 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) return;

    var imageSource = dialog.FileName;

    // Load the image into IronQR
    var inputBmp = AnyBitmap.FromFile(imageSource);

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

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

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

    // Display the first result
    var firstResult = results.FirstOrDefault();
    ResultLabel.Text = firstResult != null
        ? "Scanned Text: " + firstResult.Value
        : "No QR code found in the selected image.";
}
Imports IronQr
Imports IronSoftware.Drawing
Imports Microsoft.Win32
Imports System.Windows

Private Sub OnScanButtonClicked(sender As Object, e As RoutedEventArgs)
    ' Open a file dialog to select a QR code image
    Dim dialog As New OpenFileDialog With {
        .Title = "Select a QR code image",
        .Filter = "Image Files|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tiff"
    }

    If dialog.ShowDialog() <> True Then Return

    Dim imageSource As String = dialog.FileName

    ' Load the image into IronQR
    Dim inputBmp As AnyBitmap = AnyBitmap.FromFile(imageSource)

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

    ' 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 first result
    Dim firstResult As QrResult = results.FirstOrDefault()
    ResultLabel.Text = If(firstResult IsNot Nothing, "Scanned Text: " & firstResult.Value, "No QR code found in the selected image.")
End Sub
$vbLabelText   $csharpLabel

OpenFileDialog provides native Windows file selection filtered to common image formats. AnyBitmap.FromFile handles format decoding for PNG, JPEG, BMP, GIF, and TIFF inputs, while QrReader.Read returns an IEnumerable<QrResult> containing one entry per detected QR code. FirstOrDefault safely returns null when no QR code is found, avoiding exceptions on images without a valid code.

Output

After selecting a QR code image and clicking the scan button, the decoded value appears in the TextBlock below the button.

WPF QR Code Scanner using IronQR — decoded result displayed in the window

Decoded QR code value rendered in the WPF window

Download the Project

Click here to download the complete WpfQrScanner project.

Conclusion

IronQR integrates into a WPF application with minimal setup — a single QrReader.Read call handles the entire decoding pipeline on the desktop. To scan multiple QR codes from a single image, iterate over the full results collection instead of calling FirstOrDefault.

This same pattern extends to batch processing by looping through a directory of image files, or to real-time scanning by capturing frames from a webcam feed with a WPF media element.

For more on reading QR codes and the available scan modes, see the Read QR Codes from Image and Read QR Codes with Scan Modes guides.

Frequently Asked Questions

What is the WPF QR Code Scanner Tutorial about?

The WPF QR Code Scanner Tutorial provides a step-by-step guide to building a QR code scanner using IronQR. It explains how to use OpenFileDialog for image selection and QrReader.Read for decoding QR codes in a Windows desktop application.

How does IronQR facilitate QR code scanning in a WPF application?

IronQR simplifies QR code scanning in a WPF application by providing tools like QrReader.Read, which efficiently decodes QR codes from images selected via OpenFileDialog.

What are the main components required for building a QR code scanner in WPF?

The main components for building a QR code scanner in WPF with IronQR include the OpenFileDialog for selecting images and the QrReader.Read method for QR code decoding.

Can IronQR decode QR codes from different image formats?

Yes, IronQR can decode QR codes from various image formats, making it versatile for use in WPF applications where images might come in different file types.

Is it possible to integrate IronQR with existing WPF applications?

Absolutely, IronQR can be integrated with existing WPF applications, allowing developers to add QR code scanning capabilities without overhauling their current system.

What makes IronQR suitable for WPF development?

IronQR is suitable for WPF development due to its ease of use, robust QR code decoding capabilities, and seamless integration into Windows desktop applications.

How does the OpenFileDialog improve the user experience in a WPF QR code scanner?

The OpenFileDialog enhances user experience by providing a straightforward interface for selecting image files, which can then be processed by IronQR to decode QR codes.

What is the role of QrReader.Read in the QR code scanning process?

QrReader.Read is crucial in the QR code scanning process as it decodes the QR code from the selected image, leveraging IronQR's advanced decoding algorithms.

Are there any prerequisites for using IronQR in a WPF application?

To use IronQR in a WPF application, developers should have a basic understanding of WPF development and familiarity with C#. IronQR's straightforward API makes it accessible for developers at various skill levels.

How does IronQR ensure accuracy in QR code decoding?

IronQR ensures accuracy in QR code decoding through its advanced algorithms, which are designed to handle various QR code complexities and image qualities efficiently.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 66,059 | Version: 2026.5 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronQR
run a sample watch your URL become a QR code.