Read Barcode from Image in C#

Are you looking for an efficient method to read barcodes or QR codes from images programmatically? If you’re a developer creating a barcode scanner application in C#, you’re in the right place. Barcodes are essential in inventory management, logistics, and retail. With Aspose.BarCode for .NET, you can easily detect and extract various barcode types from images in C#. This guide provides a comprehensive, step-by-step approach to barcode recognition.

What You’ll Learn

This article covers the following topics:

  1. C# API for Barcode Reading
  2. Steps to Extract Barcode Data
  3. Read Barcode from Bitmap
  4. Read Barcode from Image Stream
  5. Detect and Read Specific Barcode Type
  6. Recognize Multiple Barcode Types
  7. Identify Predefined Barcode Sets
  8. Extract Multiple Barcodes from an Image
  9. Get Barcode Coordinates
  10. Read Barcode from a Specific Image Region
  11. Scan Barcodes from Multiple Image Regions

C# API for Barcode Reading

To recognize barcodes in images, we utilize the Aspose.BarCode for .NET API. This powerful .NET Plugin supports reading over 60 barcode symbologies across multiple formats, including JPEG, PNG, BMP, TIFF, and GIF.

The API provides the BarCodeReader class for barcode detection. You can specify symbologies using the DecodeType parameter. The ReadBarCodes() method extracts barcode data.

To install the API via NuGet, use the following command:

PM> Install-Package Aspose.BarCode

Steps to Extract Barcode Data

Follow these steps to read a barcode from an image using C#:

  1. Load an image using the BarCodeReader class.
  2. Call ReadBarCodes() to extract barcode information.
  3. Iterate through the results to get the barcode type and value.

Here’s a sample code snippet:

Read Barcode from Bitmap

To read a barcode from a bitmap using C#:

  1. Load the image using the Bitmap class.
  2. Pass it to the BarCodeReader constructor.
  3. Extract barcode data using ReadBarCodes().

Read Barcode from Image Stream

You can also read barcodes from a stream in C#:

  1. Load the image using FileStream.
  2. Pass it to the BarCodeReader.
  3. Call ReadBarCodes() to get barcode data.

Detect and Read Specific Barcode Type

To enhance efficiency when using a C# barcode reader, specify a target barcode type:

  1. Load the image in BarCodeReader.
  2. Set a specific barcode type (e.g., Code39Standard).
  3. Call ReadBarCodes() and process the results.

Recognize Multiple Barcode Types

For scanning multiple barcode types in C#, you can:

  1. Set multiple symbologies in SetBarCodeReadType().
  2. Call ReadBarCodes().
  3. Retrieve barcode data.

Identify Predefined Barcode Sets

Aspose.BarCode supports predefined barcode sets:

  • AllSupportedTypes - All available barcodes.
  • Types1D - All linear barcodes.
  • Types2D - QR Code, Data Matrix, etc.
  • MostCommonTypes - Frequently used formats.

To use predefined sets in C#:

BarCodeReader reader = new BarCodeReader("image.png", DecodeType.Types2D);

Extract Multiple Barcodes from an Image

Detect multiple barcodes from an image with the following steps:

  1. Load the image using BarCodeReader.
  2. Set the decode type to ALL_SUPPORTED_TYPES.
  3. Iterate through results to extract barcode data.

Get Barcode Coordinates

Retrieve barcode location (X, Y coordinates) with C#:

  1. Load the image in BarCodeReader.
  2. Call ReadBarCodes().
  3. Extract region points.

Read Barcode from a Specific Image Region

Limit barcode detection to a specific image region using C#:

  1. Define a rectangular area.
  2. Pass it to BarCodeReader.
  3. Call ReadBarCodes().

Scan Barcodes from Multiple Image Regions

To scan barcodes from multiple regions in C#:

  1. Define multiple rectangular areas.
  2. Pass them to BarCodeReader.
  3. Extract barcode data.

Get a Free License

Request a free temporary license to explore the full capabilities of Aspose.BarCode.

Conclusion

In this article, you learned how to:

  • Load and process barcode images.
  • Extract barcode information from different sources.
  • Detect and recognize multiple barcode types using C# barcode decoder and reader libraries like Aspose.BarCode.

By utilizing the Aspose Plugin, you can enhance your applications with powerful barcode reading capabilities for just $99. Happy coding!