VintaSoft Barcode .NET SDK v10.0
Vintasoft.WpfBarcode Namespace / BarcodeReader Class / ReadBarcodes Method / ReadBarcodes() Method
Example




In This Topic
    ReadBarcodes() Method
    In This Topic
    Reads barcodes from image specified using SetImage(Stream) method.
    Syntax
    'Declaration
     
    Public Overloads Function ReadBarcodes() As IBarcodeInfo()
    'Usage
     
    Dim instance As BarcodeReader
    Dim value() As IBarcodeInfo
     
    value = instance.ReadBarcodes()
    public IBarcodeInfo[] ReadBarcodes()
    public: IBarcodeInfo*[]* ReadBarcodes(); 
    public:
    array<IBarcodeInfo^>^ ReadBarcodes(); 
    Example
    Here is an example that demonstrates how to detect barcodes in 2 images.
    Imports Vintasoft.WpfBarcode   
    Imports Vintasoft.WpfBarcode.SymbologySubsets   
       
    ''' <summary>   
    ''' Test that shows how to read barcodes from image,   
    ''' the barcode reader searches barcodes using 2 different scan intervals.   
    ''' </summary>   
    Class ReadBarcodesFromCurrentImageExample   
       
    	''' <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)   
       
    			' specify that reader must search for horizontal and vertical barcodes only   
    			reader.Settings.ScanDirection = ScanDirection.Horizontal Or ScanDirection.Vertical   
       
    			' 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 current image with scan interval = 5   
    				Dim infos As IBarcodeInfo() = ReadBarcodes(reader, 5)   
    				' if no barcodes found   
    				If infos.Length = 0 Then   
    					' read barcodes from current image with scan interval = 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.WpfBarcode;
    using Vintasoft.WpfBarcode.SymbologySubsets;
                
    /// <summary>
    /// Test that shows how to read barcodes from image,
    /// the barcode reader searches barcodes using 2 different scan intervals.
    /// </summary>
    class ReadBarcodesFromCurrentImageExample
    {
                
        /// <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);
                
                // specify that reader must search for horizontal and vertical barcodes only
                reader.Settings.ScanDirection = ScanDirection.Horizontal | ScanDirection.Vertical;
                
                // for each filename
                foreach (string filename in filenames)
                {
                    Console.Write(string.Format("{0}: ", filename));
                
                    // set the reader image
                    reader.SetImage(filename);
                
                    // read barcodes from current image with scan interval = 5
                    IBarcodeInfo[] infos = ReadBarcodes(reader, 5);
                    // if no barcodes found
                    if (infos.Length == 0)
                        // read barcodes from current image with scan interval = 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: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also