Skip to footer content
USING IRONBARCODE

Create and Read Xamarin Barcode Images with a Modern C# Scanning Library

Xamarin barcode solutions remain essential for mobile developers maintaining Android and iOS apps in retail, logistics, and inventory management. Even though Microsoft ended official Xamarin support in May 2024, millions of Xamarin apps are still in production, and those apps still need to create, scan, and decode barcodes reliably. IronBarcode is a .NET barcode SDK that handles barcode generation and barcode reading with just a few lines of C# code. It works as a barcode scanner and generator across Android, iOS, and Windows platforms, and it transitions directly to .NET MAUI when your project migration time comes.

Start a free trial of IronBarcode and add Xamarin barcode reading to your project today.

How Does Barcode Scanning Work in Xamarin Apps?

Barcode scanning in a Xamarin app works by capturing barcode information from a camera feed or a saved file on the device, then passing that data to a scanning library that decodes the encoded information. Historically, many Xamarin developers used the open-source ZXing library (Zebra Crossing), creating a new ZXingScannerPage instance, pushing it onto the navigation stack, and handling the OnScanResult event to process barcodes. While this approach worked for basic QR code scanning use cases in Xamarin.Forms, ZXing has not received meaningful bug fixes in years, and developers frequently reported error conditions when scanning barcodes in low light or when decoding complex formats like Data Matrix.

IronBarcode is a modern barcode scanner SDK that takes a different approach. Rather than providing a dedicated scanner page with a live camera interface, IronBarcode operates on any source your Xamarin app can provide, camera captures, user-uploaded files, screenshots, or PDF documents. This makes it a flexible scanning library for Xamarin barcode projects where developers need full control over the user interface and the scanning process. The BarcodeReader class supports over 30 barcode and QR code formats, and the SDK includes built-in preprocessing filters that improve barcode scanning performance in low light conditions or with damaged barcodes.

Install the IronBarcode NuGet package into your Xamarin solution to get started:

Install-Package BarCode

The BarCode package is available on NuGet and supports .NET Standard 2.0, making it compatible with Xamarin.Forms, Xamarin native projects, and Microsoft's MAUI framework. No additional platform-specific NuGet packages or configuration steps are required for the core SDK features, install the package and test it immediately in your project.

How to Create Barcodes and QR Codes in a Xamarin App?

Generating barcodes for display on the device screen, for labeling, or for data exchange is straightforward with IronBarcode's BarcodeWriter class. The example below is a common sample for Xamarin barcode apps that need to produce both 1D and 2D barcodes.

using IronBarCode;
// Barcode generation: create a Code 128 barcode for product scanning
// Comment: BarcodeWriter handles all supported encoding formats
var barcode = BarcodeWriter.CreateBarcode(
    "PROD-2025-XMR",              // Value to encode in the barcode
    BarcodeWriterEncoding.Code128, // Barcode format for the scanner
    400, 150                       // Width and height in pixels
);
// Customize the barcode: add visible text below the barcode image
// Comment: this text helps users verify the encoded value
barcode.AddBarcodeValueTextBelowBarcode();
barcode.SaveAsPng("product_barcode.png");
// Generate a QR code that users can scan with any mobile device camera
// Comment: QR codes are ideal for URLs, contact data, and Wi-Fi config
var qrCode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com",
    BarcodeWriterEncoding.QRCode,
    300, 300
);
// Configure margins and export the QR code as image lines of pixels
qrCode.SetMargins(10);
qrCode.SaveAsPng("qr_code.png");
using IronBarCode;
// Barcode generation: create a Code 128 barcode for product scanning
// Comment: BarcodeWriter handles all supported encoding formats
var barcode = BarcodeWriter.CreateBarcode(
    "PROD-2025-XMR",              // Value to encode in the barcode
    BarcodeWriterEncoding.Code128, // Barcode format for the scanner
    400, 150                       // Width and height in pixels
);
// Customize the barcode: add visible text below the barcode image
// Comment: this text helps users verify the encoded value
barcode.AddBarcodeValueTextBelowBarcode();
barcode.SaveAsPng("product_barcode.png");
// Generate a QR code that users can scan with any mobile device camera
// Comment: QR codes are ideal for URLs, contact data, and Wi-Fi config
var qrCode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com",
    BarcodeWriterEncoding.QRCode,
    300, 300
);
// Configure margins and export the QR code as image lines of pixels
qrCode.SetMargins(10);
qrCode.SaveAsPng("qr_code.png");
$vbLabelText   $csharpLabel

Output Barcode Image

Create and Read Xamarin Barcode Images with a Modern C# Scanning Library: Image 1 - Generated barcode

The code above demonstrates IronBarcode's barcode generation in just a few lines of code, each comment in the code sample highlights the purpose of each step. It accepts the data to encode, the barcode format from the BarcodeWriterEncoding enum, and the output dimensions. IronBarcode's SDK supports a wide range of encoding types, including EAN-13, Code 39, QR code, Data Matrix, PDF417, and Aztec. After you create an instance of GeneratedBarcode, you can customize it extensively: use ResizeTo() to adjust dimensions, SetMargins() to configure padding, and AddAnnotationTextAboveBarcode() to add visible labels. You can export the generated barcodes as PNG, JPEG, GIF, TIFF, or PDF, all without writing platform-specific code for Android or iOS.

For advanced features like adding logos to QR codes or customizing barcode colors, explore the barcode generation tutorial and the create barcode code example page.

How to Read and Decode Barcodes from Camera and File Sources?

Reading barcodes from images captured by the device camera or selected from a user's photo library is where IronBarcode delivers the most value as a Xamarin barcode solution. The scanning process handles everything from pristine digital barcodes to challenging real-world camera captures with one consistent method.

using IronBarCode;
// Comment: read and decode barcodes from a camera-captured file
var results = BarcodeReader.Read("scanned_photo.png");
// Iterate through each barcode scanning result
foreach (var result in results)
{
    // Comment: access the decoded barcode value and format type
    string value = result.Value;
    string type = result.BarcodeType.ToString();
    // Display the scanned barcode data to the user on screen
    Console.WriteLine($"Type: {type}, Value: {value}");
}
using IronBarCode;
// Comment: read and decode barcodes from a camera-captured file
var results = BarcodeReader.Read("scanned_photo.png");
// Iterate through each barcode scanning result
foreach (var result in results)
{
    // Comment: access the decoded barcode value and format type
    string value = result.Value;
    string type = result.BarcodeType.ToString();
    // Display the scanned barcode data to the user on screen
    Console.WriteLine($"Type: {type}, Value: {value}");
}
$vbLabelText   $csharpLabel

Reading Barcode Data

Create and Read Xamarin Barcode Images with a Modern C# Scanning Library: Image 2 - Printed value read from uploaded barcode

This code snippet passes a file to the reader and loops over the results. Each BarcodeResult instance provides access to the barcode type, decoded text, binary data, position coordinates, and a confidence score, giving developers everything they need for production app environments. For the complete list of supported barcode types, see the barcode format support page.

For real-world use cases where barcode scanning performance matters — warehouse scanning in low light, reading damaged barcodes on a moving conveyor, or decoding multiple barcodes on a single page, the BarcodeReaderOptions class lets you configure every aspect of the reading process:

using IronBarCode;
// Comment: configure the barcode reader for challenging conditions
var options = new BarcodeReaderOptions
{
    // Comment: balance between scanning speed and accuracy on the device
    Speed = ReadingSpeed.Balanced,
    // Expect multiple barcodes per page or camera capture
    ExpectMultipleBarcodes = true,
    // Limit scanning to specific barcode types for faster results
    ExpectBarcodeTypes = BarcodeEncoding.QRCode
        | BarcodeEncoding.Code128
        | BarcodeEncoding.DataMatrix,
    // Auto-rotate barcodes captured at any camera angle
    AutoRotate = true,
    // Apply image filters to improve scanning in poor conditions
    ImageFilters = new ImageFilterCollection
    {
        new SharpenFilter(),       // Sharpen blurry camera captures
        new ContrastFilter(1.5f)   // Boost contrast for low light
    }
};
// Comment: read barcodes from a sample image using configured options
var results = BarcodeReader.Read("warehouse_scan.jpg", options);
// Iterate and display results for the user
foreach (var barcode in results)
{
    // Output each decoded barcode value from the scanner
    Console.WriteLine($"Found: {barcode.Value}");
}
using IronBarCode;
// Comment: configure the barcode reader for challenging conditions
var options = new BarcodeReaderOptions
{
    // Comment: balance between scanning speed and accuracy on the device
    Speed = ReadingSpeed.Balanced,
    // Expect multiple barcodes per page or camera capture
    ExpectMultipleBarcodes = true,
    // Limit scanning to specific barcode types for faster results
    ExpectBarcodeTypes = BarcodeEncoding.QRCode
        | BarcodeEncoding.Code128
        | BarcodeEncoding.DataMatrix,
    // Auto-rotate barcodes captured at any camera angle
    AutoRotate = true,
    // Apply image filters to improve scanning in poor conditions
    ImageFilters = new ImageFilterCollection
    {
        new SharpenFilter(),       // Sharpen blurry camera captures
        new ContrastFilter(1.5f)   // Boost contrast for low light
    }
};
// Comment: read barcodes from a sample image using configured options
var results = BarcodeReader.Read("warehouse_scan.jpg", options);
// Iterate and display results for the user
foreach (var barcode in results)
{
    // Output each decoded barcode value from the scanner
    Console.WriteLine($"Found: {barcode.Value}");
}
$vbLabelText   $csharpLabel

The Speed property controls the tradeoff between speed and accuracy, use ReadingSpeed.Faster for high-volume scanning or ReadingSpeed.Detailed for maximum detection of difficult barcodes. The ExpectBarcodeTypes configuration limits which formats the scanner SDK checks for, avoiding false-positive error results and improving performance. The AutoRotate feature automatically corrects barcodes captured at odd angles by the device camera, while SharpenFilter and ContrastFilter improve scanning barcodes in dim conditions. Developers can also use zoom-style cropping via the CropArea property to configure the scanner to focus on a specific region of a captured page.

For the complete walkthrough of all reader configuration, see the guide to reading barcodes from images and the BarcodeReaderOptions API reference. Developers who need to decode barcodes from PDF documents should also check the PDF barcode reading method.

What Are the Best Use Cases for a Mobile Barcode Solution?

Xamarin barcode and QR code scanning solutions support dozens of use cases across industries. Here are the most common scenarios where IronBarcode provides both a barcode scanner and generator that delivers value on mobile devices:

  • Inventory and warehouse management: Android and iOS device users scan barcodes on products and shelves to track stock in real time, reducing manual entry error rates and increasing speed. Any warehouse app benefits from fast, reliable barcode scanning.
  • Retail point-of-sale: QR code scanning at checkout enables rapid product lookups, coupon redemption, and mobile payment processing, all visible to the user on the app screen. The scanner function handles both 1D and 2D formats.
  • Logistics and shipping: Scanning barcodes on packages for route verification and delivery confirmation across a fleet of Android and iOS devices. IronBarcode can decode barcodes even from creased or partially obscured labels on a scanner page view.
  • Event check-in: A Xamarin app that decodes QR codes at conference gates provides instant attendee validation — no default paper tickets or manual account lookups needed. The app reads each code in under a second.
  • Healthcare: Barcodes on patient wristbands, medication labels, and lab samples are scanned by mobile devices to prevent error conditions and ensure accurate treatment by the user. Each reading page in the app can be tailored to specific barcode types.

IronBarcode provides support for all of these Xamarin barcode use cases as a comprehensive barcode scanner across platforms, including .NET Standard, .NET Core, and .NET MAUI. For developers maintaining a Xamarin barcode solution in production, IronBarcode offers ongoing support, regular updates, and clear licensing options. When migration from Xamarin to .NET MAUI is on the roadmap, IronBarcode transitions seamlessly, no code rewrites needed. See the .NET MAUI barcode scanner tutorial for a step-by-step example.

Microsoft's migration guide for moving Xamarin projects provides detailed steps for transitioning to the latest cross-platform framework. You can also find a helpful link to community solutions in this post on Stack Overflow covering common Xamarin barcode issues, and this link to the Xamarin developer community on Reddit hosts additional post discussions about mobile barcode reading approaches across platforms.

How to Get Started with Xamarin Barcode Scanning Today?

IronBarcode makes Xamarin barcode generation and barcode scanning fast, reliable, and developer-friendly. It provides support for over 30 barcode formats, advanced features like auto-rotation and customizable preprocessing, and a fluent C# interface that keeps lines of code clean and readable. Whether the solution calls for building a simple QR code sample app, processing barcodes from PDF documents, or building a full barcode reader for an Android app or iOS app, IronBarcode handles it all within a single, well-documented library. Each function in the API is designed for clarity and ease of use in production app environments.

Test IronBarcode in your Xamarin project, sign up for a free trial. When you're ready for production, explore licensing options, link to the pricing page for details starting at $749. For post-purchase support, developers can customize their coverage through the license add-ons page.

Get stated with IronBarcode now.
green arrow pointer

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 ...
Read More