Barcode Xpress for .NET Core v13.4 - Updated
Tutorial: Create Your First Project (Command Line)
Getting Started > Tutorial: Create Your First Project (Command Line)

This step-by-step tutorial will guide you to build a complete C# application that analyzes 1D barcodes using the command line and a text editor, like Visual Studio Code.

Steps:

  1. Create a new console application project from the command line by creating a directory for your project and initializing it with the dotnet new command.
    Copy Code
    mkdir MyProject
    dotnet new console
  2. Add necessary dependencies to the generated project file.
    MyProject.csproj
    Copy Code
    <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>netcoreapp2.1</TargetFramework>
     </PropertyGroup>
     <ItemGroup>
       <PackageReference Include="System.Drawing.Common" Version="4.5.0" />
       <PackageReference Include="Accusoft.BarcodeXpress13.NetCore.dll" Version="13.4.1889" />
     </ItemGroup>
    </Project>

You will need System.Drawing.Bitmap to load an image and pass it to Barcode Xpress for processing.

If you would like to use a local copy of Barcode Xpress instead of fetching one from Nuget, you can use an ItemGroup containing a reference instead of the PackageReference above:

Copy Code
<ItemGroup>
   <Reference Include="Accusoft.BarcodeXpress.NetCore">      
   <HintPath>..\BarcodeXpress\Accusoft.BarcodeXpress13.NetCore.dll</HintPath>
   </Reference>
 </ItemGroup>

Additionally, add the using statements for System.Drawing and BarcodeXpressSdk to the top of your generated Program class:

Program.cs
Copy Code
using System;
using System.Drawing;
using Accusoft.BarcodeXpressSdk;
namespace MyProject
 {
...
  1. Create an instance of the BarcodeXpress class:
    Program.cs
    Copy Code
    namespace MyProject
    {
        class Program
        {
            static void Main(string[] args)
            {
                BarcodeXpress barcodeXpress = new BarcodeXpress();
               
            }
        }
    }
  2. Acquire a System.Drawing.Bitmap object and pass it to the SDK’s Analyze method:
    Program.cs
    Copy Code
    namespace MyProject
    {
        class Program
        {
            static void Main(string[] args)
            {
                BarcodeXpress barcodeXpress = new BarcodeXpress();
                Bitmap bitmap = new Bitmap("barcode.bmp");
               
                Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap);
               
            }
        }
    }
    The simplest way to acquire a Bitmap object is to load one from a file. The Bitmap(string path) constructor loads an image from path and creates a new Bitmap object containing the image.
  3. Access the fields of returned result objects to get data about barcodes detected in the image:
    Program.cs
    Copy Code
    namespace MyProject
    {
        class Program
        {
            static void Main(string[] args)
            {
                BarcodeXpress barcodeXpress = new BarcodeXpress();
                Bitmap bitmap = new Bitmap("barcode.bmp");
               
                Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap);
               
                if (results.Length > 0)
                {
                    foreach (Accusoft.BarcodeXpressSdk.Result result in results)
                    {
                        Console.WriteLine("{0} : {1}", result.BarcodeType.ToString(), result.BarcodeValue);
                    }
                }
                else
                {
                    Console.WriteLine("No Barcodes Found.");
                }
            }
        }
    }
    BarcodeXpress.reader.Analyze returns an array of Result objects which contain information about all barcodes detected on the page. You can iterate over that array to access all known properties of each barcode.
  4. Finally, clean up the Barcode Xpress object by releasing unmanaged resources using Dispose() method:
    Program.cs
    Copy Code
    namespace MyProject
    {
        class Program
        {
            static void Main(string[] args)
            {
                BarcodeXpress barcodeXpress = new BarcodeXpress();
                Bitmap bitmap = new Bitmap("barcode.bmp");
               
                Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap);
               
                if (results.Length > 0)
                {
                    foreach (Accusoft.BarcodeXpressSdk.Result result in results)
                    {
                        Console.WriteLine("{0} : {1}", result.BarcodeType.ToString(), result.BarcodeValue);
                    }
                }
                else
                {
                    Console.WriteLine("No Barcodes Found.");
                }
                barcodeXpress.Dispose();
            }
        }
    }