VintaSoft Barcode .NET SDK 15.0: Documentation for .NET developer
Vintasoft.Barcode Namespace / BarcodeReader Class / ReadBarcodes Methods / ReadBarcodes() Method
Syntax Example Requirements SeeAlso
In This Topic
    ReadBarcodes() Method (BarcodeReader)
    In This Topic
    Reads barcodes from image specified using SetImage(Stream) method.
    Syntax
    'Declaration
    
    Public Overloads Function ReadBarcodes() As IBarcodeInfo[]
    
    
    public IBarcodeInfo[] ReadBarcodes()
    
    
    public: IBarcodeInfo*[] ReadBarcodes()
    
    
    public:
    IBarcodeInfo^[] ReadBarcodes()

    Return Value

    An array of IBarcodeInfo objects which contains information about recognized barcodes.
    Example

    Here is an example that demonstrates how to detect barcodes in 2 images.

    
    
    Imports Vintasoft.Barcode
    Imports Vintasoft.Barcode.SymbologySubsets
    
    ''' <summary>
    ''' Test that shows how to read barcodes from image,
    ''' the barcode reader searches barcodes using 2 different scan intervals.
    ''' </summary>
    Class ReadBarcodesFromImageFileExample
    
        ''' <summary>
        ''' Runs the test.
        ''' </summary>
        Public Shared Sub Test()
            ReadBarcodes("test1.jpg", "test2.png")
        End Sub
    
        ''' <summary>
        ''' Reads barcodes from images, which are stored in files.
        ''' Barcode reader will try to recognize barcodes using 2 different scan intervals.
        ''' </summary>
        Private Shared Sub ReadBarcodes(ParamArray filenames As String())
            ' create barcode reader
            Using reader As New BarcodeReader()
                ' specify that reader must search for Code39, Code39Extended,
                ' Code128, SSCC18 and DataMatrix barcodes
                reader.Settings.ScanBarcodeTypes = BarcodeType.Code39 Or BarcodeType.Code128 Or BarcodeType.DataMatrix
                reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.Code39Extended)
                reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.SSCC18)
    
                ' for each filename
                For Each filename As String In filenames
                    Console.Write(String.Format("{0}: ", filename))
    
                    ' set the reader image
                    reader.SetImage(filename)
    
                    ' read barcodes from image, scan interval is set to 5
                    Dim infos As IBarcodeInfo() = ReadBarcodes(reader, 5)
                    ' if barcodes are not found
                    If infos.Length = 0 Then
                        ' read barcodes from image, scan interval is set to 1
                        infos = ReadBarcodes(reader, 1)
                    End If
    
                    ' clear reader image
                    reader.ClearImage()
    
                    ' show barcode recognition results
    
                    If infos.Length = 0 Then
                        Console.WriteLine("No barcodes found.")
                    Else
                        Console.WriteLine(String.Format("{0} barcodes found:", infos.Length))
                        Console.WriteLine()
                        For i As Integer = 0 To infos.Length - 1
                            Dim info As IBarcodeInfo = infos(i)
                            Console.WriteLine(String.Format("[{0}:{1}]", i, info.BarcodeType))
                            Console.WriteLine(String.Format("Value:      {0}", info.Value))
                            Console.WriteLine(String.Format("Confidence: {0}%", Math.Round(info.Confidence)))
                            Console.WriteLine(String.Format("Threshold:  {0}", info.Threshold))
                            Console.WriteLine(String.Format("Region:     {0}", info.Region))
                            Console.WriteLine()
                        Next
                    End If
                Next
            End Using
        End Sub
    
        ''' <summary>
        ''' Reads barcodes from image, which is stored in barcode reader.
        ''' </summary>
        Private Shared Function ReadBarcodes(reader As BarcodeReader, scanInterval As Integer) As IBarcodeInfo()
            reader.Settings.ScanInterval = scanInterval
            Return reader.ReadBarcodes()
        End Function
    
    End Class
    
    
    
    using System;
    
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.SymbologySubsets;
    
    /// <summary>
    /// Test that shows how to read barcodes from image,
    /// the barcode reader searches barcodes using 2 different scan intervals.
    /// </summary>
    class ReadBarcodesFromImageFileExample
    {
    
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Test()
        {
            ReadBarcodes("test1.jpg", "test2.png");
        }
        
        /// <summary>
        /// Reads barcodes from images, which are stored in files.
        /// Barcode reader will try to recognize barcodes using 2 different scan intervals.
        /// </summary>
        static void ReadBarcodes(params string[] filenames)
        {
            // create barcode reader
            using (BarcodeReader reader = new BarcodeReader())
            {
                // specify that reader must search for Code39, Code39Extended,
                // Code128, SSCC18 and DataMatrix barcodes
                reader.Settings.ScanBarcodeTypes =
                    BarcodeType.Code39 |
                    BarcodeType.Code128 |
                    BarcodeType.DataMatrix;
                reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.Code39Extended);
                reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.SSCC18);
    
                // for each filename
                foreach (string filename in filenames)
                {
                    Console.Write(string.Format("{0}: ", filename));
    
                    // set the reader image
                    reader.SetImage(filename);
    
                    // read barcodes from image, scan interval is set to 5
                    IBarcodeInfo[] infos = ReadBarcodes(reader, 5);
                    // if barcodes are not found
                    if (infos.Length == 0)
                        // read barcodes from image, scan interval is set to 1
                        infos = ReadBarcodes(reader, 1);
    
                    // clear reader image
                    reader.ClearImage();
    
                    // show barcode recognition results
    
                    if (infos.Length == 0)
                    {
                        Console.WriteLine("No barcodes found.");
                    }
                    else
                    {
                        Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
                        Console.WriteLine();
                        for (int i = 0; i < infos.Length; i++)
                        {
                            IBarcodeInfo info = infos[i];
                            Console.WriteLine(string.Format("[{0}:{1}]", i, info.BarcodeType));
                            Console.WriteLine(string.Format("Value:      {0}", info.Value));
                            Console.WriteLine(string.Format("Confidence: {0}%", Math.Round(info.Confidence)));
                            Console.WriteLine(string.Format("Threshold:  {0}", info.Threshold));
                            Console.WriteLine(string.Format("Region:     {0}", info.Region));
                            Console.WriteLine();
                        }
                    }
                }
            }
        }
    
        /// <summary>
        /// Reads barcodes from image, which is stored in barcode reader.
        /// </summary>
        private static IBarcodeInfo[] ReadBarcodes(BarcodeReader reader, int scanInterval)
        {
            reader.Settings.ScanInterval = scanInterval;
            return reader.ReadBarcodes();
        }
    
    }
    
    

    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also