VintaSoft Barcode .NET SDK 15.0: Руководство для .NET разработчика
Vintasoft.Barcode Namespace / BarcodeReader Class / ReadBarcodes Methods / ReadBarcodes(String) Method
Синтаксис Example Требования Смотрите также
В этом разделе
    ReadBarcodes(String) Метод (BarcodeReader)
    В этом разделе
    Распознает штрих-коды из указанного файла.
    Синтаксис
    'Declaration
    
    Public Overloads Function ReadBarcodes( _
    ByVal filename
    Имя файла со штрих-кодами.
    As String _
    ) As IBarcodeInfo[]
    public IBarcodeInfo[] ReadBarcodes(
    string filename
    )
    public: IBarcodeInfo*[] ReadBarcodes(
    string* filename
    )
    public:
    IBarcodeInfo^[] ReadBarcodes(
    string^ filename
    )

    Parameters

    filename
    Имя файла со штрих-кодами.

    Return Value

    Массив объектов IBarcodeInfo, который содержит информацию о распознанных штрих-кодах.
    Пример

    Вот простой пример, демонстрирующий, как обнаруживать штрих-коды на изображении.

       
       
    Imports Vintasoft.Barcode   
    Imports Vintasoft.Barcode.SymbologySubsets   
       
    ''' <summary>
    ''' Test that shows how read barcodes from image, which is stored in file,
    ''' using the BarcodeReader class.
    ''' </summary>
    Class ReadBarcodesFromFilesExample   
       
        ''' <summary>
        ''' Runs the test.
        ''' </summary>
        Public Shared Sub Test()   
            ' read barcodes from image, which is stored in file
            ReadBarcodes("test1.jpg")   
        End Sub   
       
        ''' <summary>
        ''' Reads barcodes from image, which is stored in file.
        ''' </summary>
        Private Shared Sub ReadBarcodes(filename As String)   
            ' create the 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)   
       
                ' read barcodes from image stored in file
                Dim infos As IBarcodeInfo() = reader.ReadBarcodes(filename)   
       
                ' show barcode recognition results
       
                Console.WriteLine(String.Format("recognition time {0} ms.", reader.RecognizeTime.TotalMilliseconds))   
       
                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   
            End Using   
        End Sub   
       
    End Class
    
    
    
    using System;
    
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.SymbologySubsets;
    
    /// <summary>
    /// Test that shows how read barcodes from image, which is stored in file,
    /// using the BarcodeReader class.
    /// </summary>
    class ReadBarcodesFromFilesExample
    {
    
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Test()
        {
            // read barcodes from image, which is stored in file
            ReadBarcodes("test1.jpg");
        }
        
        /// <summary>
        /// Reads barcodes from image, which is stored in file.
        /// </summary>
        static void ReadBarcodes(string filename)
        {
            // create the 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);
    
                // read barcodes from image stored in file
                IBarcodeInfo[] infos = reader.ReadBarcodes(filename);
    
                // show barcode recognition results
    
                Console.WriteLine(string.Format("recognition time {0} ms.",
                    reader.RecognizeTime.TotalMilliseconds));
    
                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();
                    }
                }
            }
        }
    
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также