Decode Barcode from Image |
This is a simple example to read a barcode from an image file and decode its content.
using Opait.Barcode; // Decodes the specified barcode image file. static void DecodeBarcode(string fileName) { // Open the image file. using (var bitmap = Image.FromFile(fileName) as Bitmap) { // Create a barcode decoder class with default options. var decoder = new BarcodeDecoder(); // Detect a single barcode within the image. var result = decoder.Decode(bitmap); // Check for detection failure. if (result == null) { Console.WriteLine("Unable to find a barcode."); return; } // Display results. Console.WriteLine($"Barcode Type: {result.BarcodeType}"); Console.WriteLine($"Barcode Text: {result.Text}"); } }