Reading Barcodes and QR

C# + VB.Net: Reading Barcodes and QR Reading Barcodes and QR
using IronBarCode;
using System;
using System.Drawing;  // Include a reference to System.Drawing.Dll


/*** GET STARED WITH BARCODE READING ***/

// Read almost any Barcode or QR in 1 line of Code.
BarcodeResult QRResult = BarcodeReader.QuicklyReadOneBarcode("QR.png");

// Work with the results
if (QRResult != null)
{
    string Value = QRResult.Value;
    Bitmap Img = QRResult.BarcodeImage;
    BarcodeEncoding BarcodeType = QRResult.BarcodeType;
    byte[] Binary = QRResult.BinaryValue;
    Console.WriteLine(QRResult.Value);
}

// Setting the optional BarcodeEncoding and TryHarder settings will improve performance
BarcodeResult QRBetterResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode, true);

// Multiple Barcode Formats May be Specified using the | Pipe Operator
BarcodeResult FormatsResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode | BarcodeEncoding.PDF417 | BarcodeEncoding.Code128);



/***  READING MULTIPLE BARCODES FROM 1 IMAGE OR PDF DOCUMENT ***/

// Multiple barcodes may be scanned up from a single document or image.  A PDF document may also used as the input image
BarcodeResult[] PDFResults = BarcodeReader.QuiclyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, true);

// Work with the results
foreach (var PDFResult in PDFResults)
{
    string Value = PDFResult.Value;
    Bitmap Img = PDFResult.BarcodeImage;
    BarcodeEncoding BarcodeType = PDFResult.BarcodeType;
    byte[] Binary = PDFResult.BinaryValue;
    Console.WriteLine(PDFResult.Value);
}

// Multi frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
BarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.None);

// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs.  All threads are automatically managed by IronBarCode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);





/***  READING BARCODES FROM ONLY PART OF AN IMAGE OR DOCUMENT ***/

//  All BarcodeResult.Read methods all have counterparts that support only scanning for barcodes in specific parts of documents.
//  This really helps performance when  processing batches of similar documents, forms, tickets, financial documents etc.

System.Drawing.Rectangle MyCropArea = new Rectangle { X = 165, Y = 225, Width = 500, Height = 200 }; // measured in pixels
BarcodeResult[] InvoiceResults = BarcodeReader.ReadAllBarcodesInCropArea("Invoice.Tiff", MyCropArea, BarcodeEncoding.Code128);

//  To read barcodes from only 1 or selected pages of a PDF, the ReadBarcodesFromPdfPage and ReadBarcodesFromPdfPages methods can be used.
//  Page numbers are 1 based (the first page is  1 not zero)
PagedBarcodeResult[] Page3ScanResults = BarcodeReader.ReadBarcodesFromPdfPage("PileofInvoices.pdf", 3, BarcodeEncoding.PDF417);
Imports IronBarCode
Imports System
Imports System.Drawing ' Include a reference to System.Drawing.Dll


'''* GET STARED WITH BARCODE READING **

' Read almost any Barcode or QR in 1 line of Code.
Private QRResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png")

' Work with the results
If QRResult IsNot Nothing Then
	Dim Value As String = QRResult.Value
	Dim Img As Bitmap = QRResult.BarcodeImage
	Dim BarcodeType As BarcodeEncoding = QRResult.BarcodeType
	Dim Binary() As Byte = QRResult.BinaryValue
	Console.WriteLine(QRResult.Value)
End If

' Setting the optional BarcodeEncoding and TryHarder settings will improve performance
Dim QRBetterResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode, True)

' Multiple Barcode Formats May be Specified using the | Pipe Operator
Dim FormatsResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode Or BarcodeEncoding.PDF417 Or BarcodeEncoding.Code128)



'''*  READING MULTIPLE BARCODES FROM 1 IMAGE OR PDF DOCUMENT **

' Multiple barcodes may be scanned up from a single document or image.  A PDF document may also used as the input image
Dim PDFResults() As BarcodeResult = BarcodeReader.QuiclyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, True)

' Work with the results
For Each PDFResult In PDFResults
	Dim Value As String = PDFResult.Value
	Dim Img As Bitmap = PDFResult.BarcodeImage
	Dim BarcodeType As BarcodeEncoding = PDFResult.BarcodeType
	Dim Binary() As Byte = PDFResult.BinaryValue
	Console.WriteLine(PDFResult.Value)
Next PDFResult

' Multi frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
Dim MultiFrameResults() As BarcodeResult = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.None)

' The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs.  All threads are automatically managed by IronBarCode.
Dim ListOfDocuments = { "Image1.png", "image2.JPG", "image3.pdf" }
Dim BatchResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments)





'''*  READING BARCODES FROM ONLY PART OF AN IMAGE OR DOCUMENT **

'  All BarcodeResult.Read methods all have counterparts that support only scanning for barcodes in specific parts of documents.
'  This really helps performance when  processing batches of similar documents, forms, tickets, financial documents etc.

Dim MyCropArea As System.Drawing.Rectangle = New Rectangle With {
	.X = 165,
	.Y = 225,
	.Width = 500,
	.Height = 200
}
Dim InvoiceResults() As BarcodeResult = BarcodeReader.ReadAllBarcodesInCropArea("Invoice.Tiff", MyCropArea, BarcodeEncoding.Code128)

'  To read barcodes from only 1 or selected pages of a PDF, the ReadBarcodesFromPdfPage and ReadBarcodesFromPdfPages methods can be used.
'  Page numbers are 1 based (the first page is  1 not zero)
Dim Page3ScanResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPage("PileofInvoices.pdf", 3, BarcodeEncoding.PDF417)

The BarcodeReader.QuicklyReadOneBarcode method in the IronBarCode namespace is an incredibly useful utility for reading barcodes for in the .NET framework. By specifying a barcode encoding format, we can greatly improve performance, and by setting the TryHarder variable to True, we can cause it to automatically correct for perspective and digital noise.

The QuicklyReadAllBarcodes method is very similar; however, it can be used to read multiple barcodes for multipage documents such as PDFs or multipage TIFFs.

We can also see from this example that we may choose to only read barcodes from a specific area of a document using a System.Drawing.Rectangle. This is very useful when we’re reading barcodes from regular locations within documents such as memos, invoices, or checks.