Recognize barcodes in image in Linux using a .NET application

Blog category: Barcode.NETLinux

December 15, 2023

This article explains how to create a console .NET application and recognize barcodes in image in Ubuntu. For barcode recognition from image is used VintaSoft Barcode .NET SDK.

Here are the steps to complete that task:
  1. Open Ubuntu desktop.

  2. Create a folder, which will store the files of .NET application. Let us create "Recognize_Barcodes_In_Image" folder on current user's desktop and proceed to the folder.

  3. Open the console command terminal. This can be done choosing "Open in Terminal" item in context menu or pressing the key combination Ctrl+Alt+T.

  4. Call the command in terminal, which creates a project of new console .NET application:
    dotnet new console --framework net8.0

    The created project contains the project file "Recognize_Barcodes_In_Image.csproj" and "Program.cs" file, which contains C# code of application. Close terminal.

  5. Open the project file "Recognize_Barcodes_In_Image.csproj" in text editor and change the file text to the following text:
    <Project Sdk="Microsoft.NET.Sdk">
        <PackageReference Include="SkiaSharp" Version="2.88.6" />
        <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
        <PackageReference Include="Vintasoft.Barcode" Version="" />
        <PackageReference Include="Vintasoft.Barcode.SkiaSharp" Version="" />
        <PackageReference Include="Vintasoft.Shared" Version="" />
        <Content Include="AllSupportedBarcodes.png">

    The changed project references nuget-packages for VintaSoft Barcode .NET SDK (Vintasoft.Shared.dll, Vintasoft.Barcode.dll, Vintasoft.Barcode.SkiaSharp.dll).

  6. Open the file "Program.cs" and change its code to the following C# code:
    namespace Recognize_Barcodes_In_Image
        class Program
            static void Main(string[] args)
                // register the evaluation license for VintaSoft Barcode .NET SDK
                Vintasoft.Barcode.BarcodeGlobalSettings.Register("%EVAL_LIC_USER_NAME%", "%EVAL_LIC_USER_EMAIL%", "%EVAL_LIC_DATE%", "%EVAL_LIC_REG_CODE%");
                // Vintasoft.Barcode.SkiaSharp.dll allows to load bitmap from BMP, DNG, GIF, HEIF, JPEG, PNG, WEBP files using image codecs from SkiaSharp library
                // recognize barcodes from image file
            /// <summary>
            /// Recognizes barcodes from an image file.
            /// </summary>
            /// <param name="filename">A path to an image file.</param>
            public static void RecognizeBarcodesFromImage(string filename)
                // create barcode reader
                using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
                    // specify that reader must search for Code39, Code39Extended, Code128, SSCC18 and DataMatrix barcodes
                    reader.Settings.ScanBarcodeTypes =
                        Vintasoft.Barcode.BarcodeType.Code39 |
                        Vintasoft.Barcode.BarcodeType.Code128 |
                    // specify that reader must search for horizontal and vertical barcodes only
                    reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal | Vintasoft.Barcode.ScanDirection.Vertical;
                    // use Automatic Recognition
                    reader.Settings.AutomaticRecognition = true;
                    // read barcodes from image file
                    Vintasoft.Barcode.IBarcodeInfo[] infos = reader.ReadBarcodes(filename);
                    // if barcodes are not detected
                    if (infos.Length == 0)
                        Console.WriteLine("No barcodes found.");
                    // if barcodes are detected
                        // get information about extracted barcodes
                        Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
                        for (int i = 0; i < infos.Length; i++)
                            Vintasoft.Barcode.IBarcodeInfo info = infos[i];
                            Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
                            Console.WriteLine(string.Format("Value:      {0}", info.Value));
                            Console.WriteLine(string.Format("Region:     {0}", info.Region));

    The application code will recognize barcodes from image and output result to a console.

  7. Get the code for using evaluation version in Linux using the way described in documentation and insert the obtained code into C# code of "Program.cs" file.

  8. Copy "AllSupportedBarcodes.png" file to the project folder.

    You can use any other file containing barcodes instead of "AllSupportedBarcodes.png" file.

  9. Open terminal and compile the .NET project using the following command:
    dotnet build Recognize_Barcodes_In_Image.csproj

    Close the terminal.

  10. Go to "bin/Debug/net8.0/" folder.

  11. Open the terminal and run the .NET application using the following command:
    dotnet ./Recognize_Barcodes_In_Image.dll

    See the barcode recognition result and close the terminal.