How to read barcodes from image regsions of interest in MVC?
When using the C# ASP.NET MVC barcode reader library, you can improve barcode scanning speed by scanning only specific image regions.
The following C# code uses barcodelib barcode SDK to define a narrow scan region, attach it to EAN-13 barcode optimization settings, read a PNG image file, and enumerate decoded EAN13 barcode messages.
Create a rectangular scan area in ScanArea object from the top-left point to a bottom-right point, effectively limiting decoding to the top 20% of the image.
How to scan, detect barcodes with different types from a single image file in ASP.NET Core MVC?
When using the BarcodeLib C# Barcode Reader library, you can recognize multiple barcode symbologies on a single image simultaneously, such as Code 128 and EAN-13. This helps scan and read all different barcode types in less time.
The C# sample code below configures the barcode SDK to decode multiple symbologies, specifically CODE128 and EAN13, and then reads a PNG sample image file and enumerates the decoded message texts.
How to scan barcode using different directions in C# ASP.NET MVC app?
If your barcodes have a fixed orientation in the image, for example, all printed horizontally top-to-bottom, customizing the scanning direction of the barcode reader can improve barcode scanning speed.
Here we configure the barcode reader to decode only CODE128 symbology and restricts the read-direction order to top-to-bottom.
Call method setReadDirectionOrder() to specify the image scanning directions.
Here set the decoding direction order to top-to-bottom only. If the barcode is rotated, upside down, or scanned bottom-to-top, decoding may fail. Consider using multiple directions when input orientation is not guaranteed.
By default, the barcode scanner SDK will scan all four directions on the barcode image.
How to scan, read Unicode text from 2d barcodes in C# ASP.NET app?
2D barcodes (e.g. QR Code, Data Matrix, PDF417) can convert Unicode text into 2D barcodes via binary data. When the ASP.NET barcode reader library decodes such 2D barcodes, it is important to use the same data encoding mode as the barcode encoder.
Call method GetMessage() to decode and parse Unicode text from 2d barcodes.
Note:
The C# Barcode Scanner uses UTF-8 by default to decode and convert binary data to Unicode text. UTF-8 is the most commonly used encoding mode for 2D barcodes (QR Code, Data Matrix).
If the barcode generator uses a different encoding mode, the barcode scanner must use the same encoding for decoding.
You can use the following .NET API to specify the encoding.
How to scan, read barcode images in C# ASP.NET Core MVC web app?
Here we will step-by-step explain how to scan, read barcode images in C# ASP.NET Core web app using BarcodeLib C# Barcode Reader library.
By the end of this tutorial, you will get a simple ASP.NET Core MVC web application with barcode scanner feature enabled.
1. Create a new ASP.NET Core MVC web project
Start Visual Studio 2022 and choose Create a new project.
Select ASP.NET Core Web App (Model-View-Controller) in the dialog, and then press Next button.
In "Configure your new project" dialog, create a new project with name BarcodeLib.BarcodeReader.AspNetCore.MVC.Demo. Click Next button.
Choose Framework as .NET 8.0 (Long Term Support), and Click Create.
Now we have created a new ASP.NET Core MVC web project successfully.
2. Add Barcode Scanner library
Add the following Barcode Reader library dll and nuget package to the ASP.NET Core MVC web project.
Add barcode reader library .net standard dll BarcodeLib.BarcodeReader.Common.dll to the project reference
Search and install nuget System.Drawing.Common (latest stable version) from NuGet Package Manager in Visual Studio
3. Add C# data model classes to the ASP.NET Core MVC project
Right-click the Models folder in the Solution Explorer and choose Add > Class... to open the Add New Item dialog.
Then add a class item with name IndexViewModel.cs.
Add the following C# codes to class IndexViewModel.cs.