How to Read Barcode from Images in C#

Last Updated on 2020-08-28

Read Barcode from Images in C#

Barcode reading is an important part of many document management workflows for tracking and filtering documents. To this end, document imaging becomes an important enabler to decoding barcode scans.

This article will show you how to read 1D and 2D barcodes from an image in C#. Here we use Dynamsoft’s barcode reader SDK which provides .NET barcode APIs for you to quickly develop barcode reader software.

Below you can see a short video on how to integrate barcode scanning into a .NET application in 2 minutes:

C# Barcode Reader Demo

If you are looking for a faster and more efficient way to embed barcode reading into your .NET application, try the barcode SDK for free. The free trial installer includes a C# demo application with source code for barcode decoding. Here’s a shot of the SDK in action:

read barcode from image in c# demo

Barcode Reading C# Code

Below is the code necessary to enable barcode scanning from within your application.

To speed barcode reading, you can specify the barcode symbol type with BarcodeFormats and maximum barcode symbols to detect per image with MaxBarcodesToReadPerPage. You can get the information including barcode format, barcode content in the format of text or byte array, the region of the barcode etc.

private void btnRead_Click(object sender, EventArgs e)
            if (imageViewer.Image != null)

                BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
                    ReaderOptions ro = new ReaderOptions();
                    ro.BarcodeFormats = GetFormats();
                    ro.MaxBarcodesToReadPerPage = int.Parse(tbMaximumNum.Text);
                    reader.ReaderOptions = ro;
                    reader.LicenseKeys = "<Input your license key here>";
                    DateTime beforeRead = DateTime.Now;
                    BarcodeResult[] barcodes = reader.DecodeFile(filePath);
                    DateTime afterRead = DateTime.Now;
                    int timeElapsed = (afterRead - beforeRead).Milliseconds;
                    ShowBarcodeResults(barcodes, timeElapsed);
                catch (Exception exp)
                    MessageBox.Show(exp.Message, "Barcode Reader Demo", MessageBoxButtons.OK);

Try Barcode Reader SDK for Free

Get the 30-day free trial of the barcode reader SDK and embed barcode reading to your software.
Get 30-day free trial

We also have SDKs to help you more quickly deploy image capture and image processing applications for your web applications. Please check How to Read Barcodes Online from a Web Application for more details.

Again, contact us with any questions. And, do let us know by email or in the comments if there is anything else we can do to improve our solutions. We value your feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.