How to Scan a Barcode Image and Extract the Data in C# .NET Framework

Barcode scanning is a crucial part of many business workflows, but it can be a difficult feature to implement if you don’t take the right approach. Setting up such a system from scratch is a sure ticket to frustration and inaccuracy, as can be confirmed even by commercial-grade grocery store barcode scanners. You need a solution that can deal with skewed, improperly printed, wrinkle up barcodes, and deal with them fast!

To set up, we will bring in our package using NuGet:

Install-Package Cloudmersive.APIClient.NET.Barcode -Version 3.0.1

Now we can go ahead and call our barcode function, feeding in our input image:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.Barcode.Api;using Cloudmersive.APIClient.NET.Barcode.Client;using Cloudmersive.APIClient.NET.Barcode.Model;namespace Example{public class BarcodeScanImageExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new BarcodeScanApi();var imageFile = new System.IO.Stream(); // System.IO.Stream | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.try{// Scan an image for a barcode and turn the result.  Supported barcode types include AZTEC, CODABAR, CODE_39, CODE_93, CODE_128, DATA_MATRIX, EAN_8, EAN_13, ITF, MAXICODE, PDF_417, QR_CODE, RSS_14, RSS_EXPANDED, UPC_A, UPC_E, All_1D, UPC_EAN_EXTENSION, MSI, PLESSEY, IMBBarcodeScanResult result = apiInstance.BarcodeScanImage(imageFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling BarcodeScanApi.BarcodeScanImage: " + e.Message );}}}}

And there you have it! Easy as pie.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store