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);