How to scan, read barcode from image target regions?

How to scan, read, decode barcode from image target regions using C# in ASP.NET Core web app and Windows application?

Using Free C# Souce Code to read, decode barcode from image specified regions for ASP.NET Web Application & IIS Projects





The following content will instruct you hwo to read and scan the barcodes from one or multiple target regions in the barcode image using C# code.




Get barcode region coordinates in image

You can define one or more rectangle region(s) in an image, and the barcode scanner library will scan barcodes from these defined regions only. It will really improve the barcode scanning and reading speed and accuracy.

Defind region coordinates

To define a rectangle region inside an image, you need provide two points' coordinates of the rectangle inside the image.
  • Point One (x1, y1), the top left corner of the rectangle.
  • Point Two (x2, y2), the bottom right corner of the rectangle
The coordinate values are expressed as the percentage of the image width and height.

The origin (0,0) of the coordinate system is the upper left point of the image. The point (100, 100) is the bottom right point of the image.

The C# code below we have defined one rectangle region. It's top left corner (Point One) is the same position as the image upper left point. The rectangle width is the same as the image width, and the rectangle height is 20% of the image height.
                float x1 = 0;
                float y1 = 0;
                float x2 = 100;
                float y2 = 20;
                new SRegion(x1, y1, x2, y2);
The following C# sample code explains how to scan QR Codes from the top 20% of the image using C#.

            ScanOptions opts = new ScanOptions(BarcodeType.QRCode);

            float x1 = 0;
            float y1 = 0;
            float x2 = 100;
            float y2 = 20;
            List<SRegion> regions = new List<SRegion>();
            regions.Add(new SRegion(x1, y1, x2, y2));

            opts.SetScanRegions(regions);

            BarcodeDetail[] datas = BarcodeScanner.Scan("qrcode-barcodes.png", opts);




Scan, read barcodes from an image specified region using C#?

To improve the reading speed, you can scan and recognize barcodes from specified region in an image using C# barcode generator.

  • The below C# code will scan barcodes a rectangle region inside the barcode image.
List<SRegion> region = new List<SRegion>();
region.Add(new SRegion(0, 0, 50, 60));

string[] barcodes = BarcodeScanner.ScanRegions("qrcode-barcodes.png", BarcodeType.QRCode, region);


You can further improve the reading speed by quickly reading a single barcode from the target area inside the image file.

  • Use the method BarcodeScanner.ScanSingleBarcodeRegions() to quickly get a barcode from the target area in the image
List<SRegion> region = new List<SRegion>();
region.Add(new SRegion(0, 0, 50, 60));

string[] barcodes = BarcodeScanner.ScanSingleBarcodeRegions("qrcode-barcodes.png", BarcodeType.QRCode, region);




How to read barcodes from image multiple target regions using C#?

Sometimes the barcodes are always printed on the certain areas inside a scanned document image. You can scan and read barcodes from those target areas quickly using C# barcode reader library.

  • Here we will read barcodes from multiple specified regions in the image
List<SRegion> regions = new List<SRegion>();
regions.Add(new SRegion(0, 0, 50, 60));
regions.Add(new SRegion(100, 100, 50, 60));

string[] barcodes = BarcodeScanner.ScanRegions("qrcode-barcodes.png", BarcodeType.QRCode, regions);
















OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.