Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
With the rise of mobile applications leveraging QR Codes for quick information retrieval, the need for an efficient and easy-to-integrate QR Code scanner as well as a .NET MAUI Barcode scanner to scan Barcodes is growing. .NET MAUI (Multi-platform App UI), Microsoft's cross-platform framework, provides a unified environment for building applications across iOS, Android, macOS, and Windows. When scanning QR Codes in a .NET MAUI application, developers need an intuitive and powerful library to manage the process.
IronQR is a popular library that allows developers to generate and decode QR codes quickly, accurately, and reliably. This article will walk you through integrating IronQR with .NET MAUI to build a QR/ Barcode scanner that can work seamlessly across multiple platforms.
IronQR is a powerful, easy-to-use library that simplifies generating and decoding QR Codes in .NET applications, including .NET MAUI mobile apps for QR and Barcode scanning functionality. It provides fast and reliable solutions for integrating QR Code and Barcode scanning functionality across platforms such as iOS, Android, macOS, and Windows, which is essential for building cross-platform mobile apps.
Before proceeding with the implementation, ensure that you have the following pre-requisites:
To begin, let’s create a simple .NET MAUI project:
Select the .NET MAUI App template.
Name the project (e.g., MauiQRCodeScanner), select a location, and click Next.
Select the required .NET version and click Create.
IronQR is a third-party library that provides QR Code generation and scanning functionalities. To install IronQR, you need to add it via NuGet:
Accept any licenses and ensure that the library gets installed.
For your application to scan QR Codes, you'll need to request camera permissions on mobile platforms (iOS and Android). Here's how you can add the following permissions.
In the AndroidManifest.xml
file, add the camera permission:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
In the Info.plist
file, add the camera usage description:
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to scan QR codes</string>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to scan QR codes</string>
Now, let’s create a simple UI for our QR scanner in the MAUI Barcode scanner app. We will use the Button to trigger the scanning process and a Label to display the scanned QR Code text.
Edit the MainPage.xaml
file in the XML namespace.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MauiQRCodeScanner.MainPage">
<StackLayout Padding="20" VerticalOptions="Center">
<Button x:Name="scanButton" Text="Scan QR Code" Clicked="OnScanButtonClicked" />
<Label x:Name="resultLabel" Text="Scan Result will appear here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</ContentPage>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MauiQRCodeScanner.MainPage">
<StackLayout Padding="20" VerticalOptions="Center">
<Button x:Name="scanButton" Text="Scan QR Code" Clicked="OnScanButtonClicked" />
<Label x:Name="resultLabel" Text="Scan Result will appear here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</ContentPage>
Now, in the MainPage.xaml.cs
, you will handle the camera permissions and the QR Code scanning logic. Here’s how to implement it:
using IronQrCode;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Essentials;
namespace MauiQRCodeScanner
{
public partial class MainPage : ContentPage
{
public MainPage()
{
License.LicenseKey = "Your key"; // Add your IronQR license key here
InitializeComponent();
}
// OnScanButtonClicked method with object sender as input
private async void OnScanButtonClicked(object sender, EventArgs e)
{
// Check for camera permission
var status = await Permissions.RequestAsync<Permissions.Camera>();
if (status != PermissionStatus.Granted)
{
await DisplayAlert("Permission Denied", "Cannot scan QR codes without camera permission", "OK");
return;
}
// Start scanning QR codes
try
{
var images = await FilePicker.Default.PickAsync(new PickOptions
{
PickerTitle = "Pick image",
FileTypes = FilePickerFileType.Images
});
var imageSource = images.FullPath.ToString();
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);
if (results.Any())
{
resultLabel.Text = "Scanned Text: " + results.First().Value;
// Display the result
}
else
{
resultLabel.Text = "No QR code detected";
}
}
catch (Exception ex)
{
resultLabel.Text = "Error: " + ex.Message;
}
}
}
}
using IronQrCode;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Essentials;
namespace MauiQRCodeScanner
{
public partial class MainPage : ContentPage
{
public MainPage()
{
License.LicenseKey = "Your key"; // Add your IronQR license key here
InitializeComponent();
}
// OnScanButtonClicked method with object sender as input
private async void OnScanButtonClicked(object sender, EventArgs e)
{
// Check for camera permission
var status = await Permissions.RequestAsync<Permissions.Camera>();
if (status != PermissionStatus.Granted)
{
await DisplayAlert("Permission Denied", "Cannot scan QR codes without camera permission", "OK");
return;
}
// Start scanning QR codes
try
{
var images = await FilePicker.Default.PickAsync(new PickOptions
{
PickerTitle = "Pick image",
FileTypes = FilePickerFileType.Images
});
var imageSource = images.FullPath.ToString();
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);
if (results.Any())
{
resultLabel.Text = "Scanned Text: " + results.First().Value;
// Display the result
}
else
{
resultLabel.Text = "No QR code detected";
}
}
catch (Exception ex)
{
resultLabel.Text = "Error: " + ex.Message;
}
}
}
}
Permissions.RequestAsync<Permissions.Camera>()
. If the permission is denied, the user is shown an alert.QrReader.Read()
method attempts to decode the QR Codes, and the result is shown on the label.Select the required QR Code or capture it from the Camera feed.
The result is displayed in the UI as below.
IronQR works with a license key in the mobile app code. Developers can easily get a trial license from the license page. Place the license somewhere in the code as below before using the IronQR library.
License.LicenseKey = "Your License";
License.LicenseKey = "Your License";
In this article, we walked through the process of building a QR Code scanner in a .NET MAUI application using IronQR. We started by setting up a .NET MAUI app, installed the IronQR package, and implemented the UI and scanning logic. IronQR makes QR Code scanning in a .NET MAUI app incredibly simple and effective.
IronQR library is designed to be cross-platform, ensuring that apps built with .NET MAUI can access QR Code functionality consistently across all target devices, whether they are smartphones, tablets, or desktop systems. IronQR also supports features like automatic camera permission handling, making it easier to integrate QR Code scanning without the hassle of managing permissions manually.
In short, IronQR for .NET MAUI enables developers to quickly implement QR Code scanning and generation features in their mobile apps, streamlining development and improving the user experience across all platforms.
.NET MAUI (Multi-platform App UI) is Microsoft's cross-platform framework that provides a unified environment for building applications across iOS, Android, macOS, and Windows.
IronQR is a powerful library that allows developers to generate and decode QR codes quickly, accurately, and reliably in .NET applications, including .NET MAUI mobile apps.
To start a .NET MAUI project, open Visual Studio, create a new project and select the .NET MAUI App template. Name the project and select the required .NET version.
In Visual Studio, right-click on your project's Dependencies, click Manage NuGet Packages, search for IronQR, and click Install on the relevant package.
For QR scanning, you need camera permissions. On Android, add camera permissions in the AndroidManifest.xml file. On iOS, add a camera usage description in the Info.plist file.
IronQR features include cross-platform support, efficient QR Code and Barcode scanning, QR Code generation, automatic camera permission handling, high performance, customizable settings, easy integration, error handling, no external dependencies, and multi-format support.
Use Permissions.RequestAsync
In your .NET MAUI app, use IronQR library objects and methods like QrReader.Read() to decode QR Codes and display the result in the app's UI.
You can obtain an IronQR license key from the IronQR license page. Place the license key in your code before using the IronQR library.
Ensure you have Visual Studio 2022 or later, .NET 6.0 SDK or later, and the IronQR NuGet Package for QR Code scanning and Barcode detection.