Recognize barcodes in image in console .NET application
In This Topic
This tutorial shows how to create a blank console .NET application in Visual Studio .NET 2022 and recognize barcodes in image in console .NET application.
Here are steps, which must be done:
-
Create a blank console .NET application.
Open Visual Studio .NET 2022 and create a new project, of "Console application" type:
Configure the project to use .NET 8.0:
-
Add references to the Vintasoft assemblies to the console .NET application.
-
Add references to the Vintasoft assemblies from the installation of the SDK evaluation version.
If the evaluation version of VintaSoft Barcode .NET SDK is not installed on your Windows computer, please download the evaluation version of VintaSoft Barcode .NET SDK from here and install the evaluation version of VintaSoft Barcode .NET SDK to your Windows computer.
Add references to the Vintasoft.Barcode.dll and Vintasoft.Shared.dll assemblies from folder "<InstallPath>\VintaSoft Barcode .NET 15.2\Bin\DotNet8\AnyCPU\" to your console .NET application:
- In Solution Explorer, locate the project.
- Right-click the "Dependencies" node. => Context menu will appear.
- Select "Add Project Reference..." menu in context menu. => The "Reference Manager" dialog will appear.
- In the "Reference Manager" dialog navigate to the "Browse" tab, click the "Browse..." button. => File selection dialog will appear.
- Select the desired .NET assembly files (Vintasoft.Barcode.dll and Vintasoft.Shared.dll) in folder "<InstallPath>\VintaSoft Barcode .NET 15.2\Bin\DotNet8\AnyCPU\" and click "Add" button => File selection dialog will be closed.
- Click "OK" button. => The "Reference Manager" dialog will be closed. => References to Vintasoft assemblies will be added to the console .NET project.
-
Add references to the Vintasoft assemblies from Vintasoft nuget-packages.
Add references to the Vintasoft.Barcode.dll and Vintasoft.Shared.dll assemblies from Vintasoft nuget-packages to your console .NET application:
- In Solution Explorer, locate the project.
- Right-click the "Dependencies" node. => Context menu will appear.
- Select "Manage Nuget Packages..." menu in context menu. => The "Nuget Package Manager" dialog will appear.
- In the "Nuget Package Manager" dialog navigate to the "Browse" tab, enter "vintasoft" text in search text field. => Vintasoft nuget-packages will be shown in the package list.
- Select "Vintasoft.Shared" package in the package list and click the "Install" button. => Reference to the "Vintasoft.Shared" nuget-package will be added to the console .NET project.
- Select "Vintasoft.Barcode" package in the package list and click the "Install" button. => Reference to the "Vintasoft.Barcode" nuget-package will be added to the console .NET project.
- Close the "Nuget Package Manager" dialog.
-
Add image with barcodes to the project.
Copy image file with barcodes, for example image file "[SdkInstallPath]\VintaSoft\Barcode .NET 15.2\Images\AllSupportedBarcodes.png" to the project folder.
In the "Properties" grid set the "Copy to Output Directory" parameter of image file to the "Copy always" value. After this Visual Studio will copy file to the output directory each time when project is executing.
-
Add C# code that registers the evaluation version for VintaSoft Barcode .NET SDK.
Get C# code for using evaluation version in Windows using the way described in documentation and insert the obtained code in the Main method of "Program.cs" file.
Here is C# code that registers the evaluation version for VintaSoft Barcode .NET SDK:
static void Main(string[] args)
{
// register the evaluation license for VintaSoft Barcode .NET SDK
Vintasoft.Barcode.BarcodeGlobalSettings.Register("EVAL_USER", "EVAL_USER_EMAIL", "EVAL_END_DATE", "EVAL_REG_CODE");
}
-
Add C# code that recognizes barcodes in image.
Open file "Program.cs" and add C# code, which recognizes barcodes in image, to the Main method.
Here is C# code that recognizes Code128 and DataMatrix barcodes in image:
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
// register the evaluation license for VintaSoft Barcode .NET SDK
//Vintasoft.Barcode.BarcodeGlobalSettings.Register("EVAL_USER", "EVAL_USER_EMAIL", "EVAL_END_DATE", "EVAL_REG_CODE");
// open a PNG-file that contains image with barcodes
using (FileStream fileStream = new FileStream("AllSupportedBarcodes.png", FileMode.Open, FileAccess.Read))
{
// create barcode reader
using (Vintasoft.Barcode.BarcodeReader barcodeReader = new Vintasoft.Barcode.BarcodeReader())
{
// specify that barcode reader must recognize Code128 and DataMatrix barcodes
barcodeReader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.Code128 | Vintasoft.Barcode.BarcodeType.DataMatrix;
// recognize barcodes in PNG file that is stored in memory stream
Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = barcodeReader.ReadBarcodes(fileStream);
// if barcode is not recognized
if (barcodeInfos.Length == 0)
{
Console.WriteLine("Barcode Reader", "Barcode is not recognized.", "OK");
}
// if barcode is recognized
else
{
Console.WriteLine("Recognized barcodes: ");
// for each recognized barcode
for (int i = 0; i < barcodeInfos.Length; i++)
{
// display information about recognized barcode
Console.WriteLine(string.Format("- Type='{0}', Value='{1}'", barcodeInfos[i].BarcodeType, barcodeInfos[i].Value));
}
}
}
}
}
}
}
-
Run console .NET application in Visual Studio and see the result.