VintaSoft Barcode .NET SDK 14.3: Documentation for .NET developer
In This Topic
    Read barcodes from image file
    In This Topic
    The SDK allows to load bitmap from file or stream and recognize barcodes in loaded bitmap.

    Vintasoft.Barcode.dll allows to load bitmap from BMP, JPEG, PNG files using built-in image codecs.

    Vintasoft.Barcode.dll + Vintasoft.Barcode.Gdi.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from System.Drawing library.

    Vintasoft.Barcode.dll + Vintasoft.Barcode.Wpf.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from WPF.

    Vintasoft.Barcode.dll + Vintasoft.Barcode.ImageSharp.dll allows to load bitmap from BMP, JPEG, PBM, PNG, TGA, TIFF, WEBP files using image codecs from SixLabors.ImageSharp library.

    Vintasoft.Barcode.dll + Vintasoft.Barcode.SkiaSharp.dll allows to load bitmap from BMP, DNG, GIF, HEIF, JPEG, PNG, WEBP files using image codecs from SkiaSharp library.

    Example: Here is an example that shows how to read barcodes from an image file.
    /// <summary>
    /// Allows to read barcodes from image file.
    /// </summary>
    public static class ImageFileBarcodeReader
    {
        /// <summary>
        /// Initializes the <see cref="ImageFileBarcodeReader"/> class.
        /// </summary>
        static ImageFileBarcodeReader()
        {
            // Vintasoft.Barcode.dll allows to load bitmap from BMP, JPEG, PNG files using built-in image codecs
            
            // Uncomment initialization of platform extension below, if necessary:
    
            // Vintasoft.Barcode.Gdi.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from System.Drawing library
            //Vintasoft.Barcode.GdiAssembly.Init();
    
            // Vintasoft.Barcode.Wpf.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from WPF
            //Vintasoft.Barcode.WpfAssembly.Init();
    
            // Vintasoft.Barcode.ImageSharp.dll allows to load bitmap from BMP, JPEG, PBM, PNG, TGA, TIFF, WEBP files using image codecs from SixLabors.ImageSharp library
            //Vintasoft.Barcode.ImageSharpAssembly.Init();
    
            // Vintasoft.Barcode.SkiaSharp.dll allows to load bitmap from BMP, DNG, GIF, HEIF, JPEG, PNG, WEBP files using image codecs from SkiaSharp library
            //Vintasoft.Barcode.SkiaSharpAssembly.Init();
        }
    
        /// <summary>
        /// Reads barcodes from an image file.
        /// </summary>
        /// <param name="filename">A path to an image file.</param>
        public static void ReadBarcodesFromImage(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 |
                    Vintasoft.Barcode.BarcodeType.DataMatrix;
                reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.Code39Extended);
                reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.SSCC18);
    
                // 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
                else
                {
                    // get information about extracted barcodes
    
                    Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
                    Console.WriteLine();
                    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));
                        Console.WriteLine();
                    }
                }
            }
        }
    }
    
    ''' <summary>
    ''' Allows to read barcodes from image file.
    ''' </summary>
    Public NotInheritable Class ImageFileBarcodeReader
        Private Sub New()
        End Sub
    
        ''' <summary>
        ''' Initializes the <see cref="ImageFileBarcodeReader"/> class.
        ''' </summary>
                ' Vintasoft.Barcode.dll allows to load bitmap from BMP, JPEG, PNG files using built-in image codecs
    
                ' Uncomment initialization of platform extension below, if necessary:
    
                ' Vintasoft.Barcode.Gdi.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from System.Drawing library
                'Vintasoft.Barcode.GdiAssembly.Init();
    
                ' Vintasoft.Barcode.Wpf.dll allows to load bitmap from BMP, GIF, JPEG, PNG, TIFF files using image codecs from WPF
                'Vintasoft.Barcode.WpfAssembly.Init();
    
                ' Vintasoft.Barcode.ImageSharp.dll allows to load bitmap from BMP, JPEG, PBM, PNG, TGA, TIFF, WEBP files using image codecs from SixLabors.ImageSharp library
                'Vintasoft.Barcode.ImageSharpAssembly.Init();
    
                ' Vintasoft.Barcode.SkiaSharp.dll allows to load bitmap from BMP, DNG, GIF, HEIF, JPEG, PNG, WEBP files using image codecs from SkiaSharp library
                'Vintasoft.Barcode.SkiaSharpAssembly.Init();
        Shared Sub New()
        End Sub
    
        ''' <summary>
        ''' Reads barcodes from an image file.
        ''' </summary>
        ''' <param name="filename">A path to an image file.</param>
        Public Shared Sub ReadBarcodesFromImage(filename As String)
            ' create barcode reader
            Using reader As New Vintasoft.Barcode.BarcodeReader()
                ' specify that reader must search for Code39, Code39Extended,
                ' Code128, SSCC18 and DataMatrix barcodes
                reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.Code39 Or Vintasoft.Barcode.BarcodeType.Code128 Or Vintasoft.Barcode.BarcodeType.DataMatrix
                reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.Code39Extended)
                reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.SSCC18)
    
                ' specify that reader must search for horizontal and vertical barcodes only
                reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal Or Vintasoft.Barcode.ScanDirection.Vertical
    
                ' use Automatic Recognition
                reader.Settings.AutomaticRecognition = True
    
                ' read barcodes from image file
                Dim infos As Vintasoft.Barcode.IBarcodeInfo() = reader.ReadBarcodes(filename)
    
                ' if barcodes are not detected
                If infos.Length = 0 Then
                    Console.WriteLine("No barcodes found.")
                Else
                    ' if barcodes are detected
                    ' get information about extracted barcodes
    
                    Console.WriteLine(String.Format("{0} barcodes found:", infos.Length))
                    Console.WriteLine()
                    For i As Integer = 0 To infos.Length - 1
                        Dim info As Vintasoft.Barcode.IBarcodeInfo = 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))
                        Console.WriteLine()
                    Next
                End If
            End Using
        End Sub
    End Class