USING IRONQR

Introduction to IronQR

How to Scan QR Codes in C#: Figure 1 - IronQR homepage

As a C# QR code scanner, IronQR is a powerful library that makes the tasks of QR operations straightforward. Designed specifically for C# and .NET, IronQR provides a simple API for both generating and scanning QR codes, ensuring you can quickly integrate this functionality into your projects.

IronQR stands out for its ease of use and flexibility. Whether you're developing a desktop application, a web service, or a mobile app, IronQR offers the tools you need. It supports various QR code formats, even providing multipage images such as gif images, and provides high-speed processing, making it a reliable choice for any project. In this article, we'll cover setting up IronQR, basic QR code scanning, and some advanced features. By the end, you'll be ready to use IronQR to enhance your applications with QR code capabilities.

Reading QR Codes Using IronQR

  1. Setup C# Console Project in Visual Studio.
  2. Install the C# QR Code library in the C# Project.
  3. Import Required namespace.
  4. Load the QR into the program.
  5. Scan the QR using the C# QR Code Library.
  6. Display the QR Code value on the console.

Setting Up IronQR in Your C# Project

Prerequisites for Using IronQR

Before integrating IronQR into your C# project, ensure you have the following prerequisites:

  • Visual Studio: An up-to-date version installed on your machine.
  • .NET Framework: IronQR is compatible with .NET Framework 4.0 and above, so make sure your project targets a compatible version.
  • NuGet Package Manager: IronQR is distributed via NuGet, so you need NuGet Package Manager in Visual Studio.

Installing IronQR via NuGet

To install IronQR, follow these steps:

  1. Open your project in Visual Studio.
  2. Navigate to the NuGet Package Manager: Right-click on your project in the Solution Explorer and select "Manage NuGet Packages."
  3. Search for IronQR: In the NuGet Package Manager, type "IronQR" in the search bar.
  4. Install IronQR: Select the IronQR package from the search results and click "Install."

Alternatively, you can install IronQR using the NuGet Package Manager Console with the following command:

Install-Package IronQR

This command downloads and adds IronQR to your project, making its functionalities available for you to use. After installing IronQR, you can start using it in your project. Ensure you include the necessary directives and configure any initial settings required by your application.

Steps to Scan QR Code in C#

Using Namespaces and Class Structure

To begin, it's essential to include the necessary namespaces and set up the class structure for your C# application. This ensures that all required libraries and classes are available for use. The IronQRCode and IronSoftware.Drawing namespaces are included for their respective functionalities. The class is defined within the Program class, and the Main method serves as the entry point of the application.

using IronQRCode;
using IronSoftware.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // The main method is the program's entry point
    }
}
using IronQRCode;
using IronSoftware.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // The main method is the program's entry point
    }
}
Imports IronQRCode

Imports IronSoftware.Drawing



Friend Class Program

	Shared Sub Main(ByVal args() As String)

		' The main method is the program's entry point

	End Sub

End Class
$vbLabelText   $csharpLabel

Loading the QR Code Image from the File

The first step in our QR code scanning process is to load the image that contains the QR code. In this example, we use the AnyBitmap class from IronSoftware.Drawing namespace. The AnyBitmap.FromFile method allows us to load an image from a specified file path.

This method is flexible and can handle various image formats. Here, the QR code image is located on the user's desktop at the path QR.png. By calling AnyBitmap.FromFile("QR.png"), we load the image and store it in the qrImage variable. This variable now contains the image data, which will be used in subsequent steps.

// Load the QR code image from the file path
var qrImage = AnyBitmap.FromFile("QR.png");
// Load the QR code image from the file path
var qrImage = AnyBitmap.FromFile("QR.png");
' Load the QR code image from the file path

Dim qrImage = AnyBitmap.FromFile("QR.png")
$vbLabelText   $csharpLabel

Initializing the QR Code Image Input

After loading the image, the next step is to create a QrCode object. This object serves as the input for the QR code reader. The QrCode class is designed to encapsulate the image and prepare it for scanning. By initializing the QrCode object with the loaded image (qrImage), we ensure that the image is correctly formatted and ready to be processed by the QR code reader.

// Setting the image as a QR input
var qrImageInput = new QrCode(qrImage);
// Setting the image as a QR input
var qrImageInput = new QrCode(qrImage);
' Setting the image as a QR input

Dim qrImageInput = New QrCode(qrImage)
$vbLabelText   $csharpLabel

Creating a QR Code Reader

To read the QR code from the image, we need a QR code reader. This is achieved by creating an instance of the BarcodeReader class. The BarcodeReader class is designed to handle the process of decoding QR codes from various input sources, including images.

By instantiating the BarcodeReader class with BarcodeReader qrReader = new BarcodeReader();, we set up a QR code reader that is capable of processing the QR code image input and extracting the encoded information. The BarcodeReader instance is now ready to perform the scanning operation.

// Instantiate a QR reader for processing the image input
var qrReader = new BarcodeReader();
// Instantiate a QR reader for processing the image input
var qrReader = new BarcodeReader();
' Instantiate a QR reader for processing the image input

Dim qrReader = New BarcodeReader()
$vbLabelText   $csharpLabel

Reading the QR Code from the Image Input

With the QR code reader initialized, we can proceed to read the QR code from the image input. This is done using the Read method of the BarcodeReader class. The Read method takes the QrCode object as a parameter and returns an IEnumerable<QrResult> containing the results of the QR code scanning.

The code IEnumerable<QrResult> qrResults = qrReader.Read(qrImageInput); executes the reading process and stores the results in the qrResults variable. This variable now holds a collection of QR code results, each representing a QR code found in the image.

// Execute the scanning process and store results
IEnumerable<QrResult> qrResults = qrReader.Read(qrImageInput);
// Execute the scanning process and store results
IEnumerable<QrResult> qrResults = qrReader.Read(qrImageInput);
' Execute the scanning process and store results

Dim qrResults As IEnumerable(Of QrResult) = qrReader.Read(qrImageInput)
$vbLabelText   $csharpLabel

Extracting the Value of the First QR Code Found

After reading the QR codes from the image, the next step is to extract the value of the first QR code found. This is typically the data encoded in the QR code, such as a URL, text, or other information. The qrResults variable holds a collection of QR code results, and we use the First method to access the first result in the collection.

The code var qrCodeValue = qrResults.First().Value; retrieves the value of the first QR code and stores it in the qrCodeValue variable. This variable now contains the decoded information from the QR code, which can be used as needed.

// Get the value of the first QR code found
var qrCodeValue = qrResults.First().Value;
// Get the value of the first QR code found
var qrCodeValue = qrResults.First().Value;
' Get the value of the first QR code found

Dim qrCodeValue = qrResults.First().Value
$vbLabelText   $csharpLabel

Printing the QR Code Value to the Console

Finally, we print the extracted QR code value to the console to verify that the QR code has been read and decoded correctly. This is done using the Console.WriteLine method, which outputs the value to the console window.

The code Console.WriteLine(qrCodeValue); displays the decoded QR code value, allowing us to confirm that the QR code scanning process was successful. This step is crucial for debugging and ensuring that the application correctly interprets the QR code data.

// Output the decoded value to the console
Console.WriteLine(qrCodeValue);
// Output the decoded value to the console
Console.WriteLine(qrCodeValue);
' Output the decoded value to the console

Console.WriteLine(qrCodeValue)
$vbLabelText   $csharpLabel

How to Scan QR Codes in C#: Figure 2 - Extracted URL value from the QR code input from the code example above using IronQR

Real-World Example

QR codes have become popular in digital payment systems. Customers can make payments by scanning a QR code with their mobile devices. Financial institutions and payment service providers can integrate IronQR into their C# applications to facilitate secure and swift transactions. The QR codes can contain payment details, which, when scanned, complete the transaction seamlessly.

Conclusion

How to Scan QR Codes in C#: Figure 3 - IronQR licensing page

IronQR is a powerful tool for C# developers looking to add QR code scanning and generation capabilities to their applications. Its ease of use, flexibility, and robust feature set make it an ideal choice for various real-world applications, from event management and inventory tracking to digital payments and marketing campaigns. It can scan QR codes from the video stream as well. Similarly, if you are looking for a library for reading barcodes, you should visit IronBarcode offering similar functionality and flexibility as a powerful barcode reader.

IronQR offers a free trial, allowing you to explore its features before committing to a purchase. If you decide to use IronQR for your projects, licenses start at $749, providing a cost-effective solution for integrating advanced QR code functionality into your applications. Whether you're building a small project or a large-scale enterprise application, IronQR equips you with the tools you need to succeed.

Frequently Asked Questions

What is IronQR?

IronQR is a powerful library designed for C# and .NET that simplifies QR code operations, providing a straightforward API for generating and scanning QR codes.

How do I install IronQR in my C# project?

You can install IronQR via the NuGet Package Manager in Visual Studio. Search for 'IronQR' in the package manager and click 'Install.' Alternatively, use the NuGet Package Manager Console with the command: Install-Package IronQR.

What are the prerequisites for using IronQR?

To use IronQR, you need Visual Studio, a compatible version of the .NET Framework (4.0 and above), and the NuGet Package Manager.

Can IronQR handle different QR code formats?

Yes, IronQR supports various QR code formats, including multipage images like gif images, and offers high-speed processing.

What are the steps to scan a QR code using IronQR in C#?

The steps include setting up a C# console project, installing IronQR, importing the necessary namespaces, loading the QR image, scanning it using IronQR, and displaying the result in the console.

What is the purpose of the BarcodeReader class in IronQR?

The BarcodeReader class in IronQR is used to decode QR codes from various input sources, including images, and extract the encoded information.

How can IronQR be used in real-world applications?

IronQR can be used in applications for event management, inventory tracking, digital payments, and marketing campaigns, providing reliable QR code scanning and generation capabilities.

Is there a trial available for IronQR?

Yes, IronQR offers a free trial allowing developers to explore its features before purchase. Licenses start at an affordable price for those who decide to integrate it into their projects.

Can IronQR scan QR codes from video streams?

Yes, IronQR is capable of scanning QR codes from video streams, making it flexible for various applications.

What other similar libraries does IronSoftware offer?

IronSoftware also offers IronBarcode, which provides similar functionality to IronQR but is focused on reading and generating barcodes.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.
< PREVIOUS
How to Scan QR Code in ASP .NET
NEXT >
How to read QR Codes in C#

Ready to get started? Version: 2025.6 just released

View Licenses >