VintaSoft Barcode .NET SDK 15.0: Руководство для .NET разработчика
Vintasoft.Barcode Namespace / ReaderSettings Class / VerifyBarcodeMethod Property
Синтаксис Ремарки Example Требования Смотрите также
В этом разделе
    VerifyBarcodeMethod Свойство (ReaderSettings)
    В этом разделе
    Возвращает или задает метод, который проверяет информацию о штрих-коде, найденном распознавателем штрих-кодов.
    Синтаксис
    'Declaration
    
    <XmlIgnoreAttribute()>
    Public Property VerifyBarcodeMethod As VerifyBarcodeDelegate
    
    
    [XmlIgnore()]
    public VerifyBarcodeDelegate VerifyBarcodeMethod { get; set; }
    
    
    [XmlIgnore()]
    public: __property VerifyBarcodeDelegate* get_VerifyBarcodeMethod();
    public: __property void set_VerifyBarcodeMethod(
    VerifyBarcodeDelegate* value
    );
    [XmlIgnore()]
    public:
    property VerifyBarcodeDelegate^ VerifyBarcodeMethod { VerifyBarcodeDelegate^ get(); void set(VerifyBarcodeDelegate^ value); }
    Ремарки

    Метод, который проверяет информацию о штрих-коде, найденном распознавателем штрих-кодов, выполняется каждый раз, когда "штрих-код" обнаруживается распознавателем штрих-кодов.

    Приложение может анализировать информацию о найденном штрих-коде и изменять Confidence, если это необходимо.

    Метод проверки информации о найденном штрих-коде можно использовать в автоматическом или итерационном режиме распознавания и повысить качество распознавания.

    Пример

    Этот C#/VB.NET код показывает, как сгенерировать штрих-код Code 39 с пользовательской контрольной суммой по основанию 1000 и распознать сгенерированный штрих-код с помощью метода проверки контрольной суммы штрих-кода.

       
       
    Imports Vintasoft.Barcode   
    Imports Vintasoft.Imaging   
       
    ''' <summary>
    ''' Test that shows how to set the delegate for barcode verification and
    ''' verify found barcodes during the barcode recognition process.
    ''' </summary>
    Class UserDefinedChecksumExample   
        ''' <summary>
        ''' Runs the test.
        ''' </summary>
        Public Shared Sub Run()   
            Dim value As String = "1234567890AbC"   
       
            ' create the barcode writer
            Using writer As New BarcodeWriter()   
                ' specify that writer must generate Code39 barcode
                writer.Settings.Barcode = BarcodeType.Code39   
       
                ' create the barcode reader
                Using reader As New BarcodeReader()   
                    ' specify that reader must search for Code39 barcodes only
                    reader.Settings.ScanBarcodeTypes = BarcodeType.Code39   
                    ' specify that reader must search for barcode with 100% confidence only
                    reader.Settings.MinConfidence = 100   
                    ' specify that reader must use barcodes in automatic mode
                    reader.Settings.AutomaticRecognition = True   
                    ' specify that reader must search for 1 barcode
                    reader.Settings.ExpectedBarcodes = 1   
       
                    ' set the barcode value without checksum
                    writer.Settings.Value = value   
                    ' create image with barcode without checksum
                    Using barcodeNoChecksumImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()   
                        ' set the barcode value with checksum
                        writer.Settings.Value = value & GenerateChecksum(value)   
                        ' create image with barcode with checksum
                        Using barcodeWithMyChecksumImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()   
                            ' specify delegate to a method for barcode verification
                            reader.Settings.VerifyBarcodeMethod = AddressOf VerifyBarcodeMethod   
       
                            ' read barcodes from barcode image without checksum,
                            ' barcode reader will not find barcode
                            Dim infos As IBarcodeInfo() = reader.ReadBarcodes(barcodeNoChecksumImage)   
                            Console.WriteLine("Scan (NoChecksum):")   
                            For i As Integer = 0 To infos.Length - 1   
                                Console.WriteLine(infos(i).Value)   
                            Next   
       
                            ' read barcodes from barcode image with checksum,
                            ' barcode reader will find 1 barcode
                            infos = reader.ReadBarcodes(barcodeWithMyChecksumImage)   
                            Console.WriteLine("Scan (MyChecksum):")   
                            For i As Integer = 0 To infos.Length - 1   
                                Console.WriteLine(infos(i).Value)   
                            Next   
                        End Using   
                    End Using   
                End Using   
            End Using   
        End Sub   
       
        ''' <summary>
        ''' Generates checksum modulo 1000.
        ''' </summary>
        Private Shared Function GenerateChecksum(value As String) As String   
            Dim checkSum As Integer = 0   
            For i As Integer = 0 To value.Length - 1   
                checkSum += CByte(AscW(value(i))) * (i + 1)   
                checkSum = checkSum Mod 1000   
            Next   
            ' result - [000..999]
            Return checkSum.ToString().PadLeft(3, "0"C)   
        End Function   
       
        ''' <summary>
        ''' Verifies the barcode during the barcode recognition process.
        ''' </summary>
        Private Shared Sub VerifyBarcodeMethod(reader As BarcodeReader, barcodeInfo As IBarcodeInfo)   
            If TestChecksum(barcodeInfo.Value) Then   
                barcodeInfo.Confidence = 100   
            Else   
                barcodeInfo.Confidence = 0   
            End If   
        End Sub   
       
        ''' <summary>
        ''' Tests checksum in barcode value.
        ''' </summary>
        Private Shared Function TestChecksum(barcodeValue As String) As Boolean   
            Dim value As String = barcodeValue.Substring(0, barcodeValue.Length - 3)   
            Dim readChecksum As String = barcodeValue.Substring(barcodeValue.Length - 3)   
            Return readChecksum = GenerateChecksum(value)   
        End Function   
       
    End Class
    
    
    
    using System;
    
    using Vintasoft.Barcode;
    using Vintasoft.Imaging;
    
    /// <summary>
    /// Test that shows how to set the delegate for barcode verification and
    /// verify found barcodes during the barcode recognition process.
    /// </summary>
    class UserDefinedChecksumExample
    {
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Run()
        {
            string value = "1234567890AbC";
    
            // create the barcode writer
            using (BarcodeWriter writer = new BarcodeWriter())
            {
                // specify that writer must generate Code39 barcode
                writer.Settings.Barcode = BarcodeType.Code39;
    
                // create the barcode reader
                using (BarcodeReader reader = new BarcodeReader())
                {
                    // specify that reader must search for Code39 barcodes only
                    reader.Settings.ScanBarcodeTypes = BarcodeType.Code39;
                    // specify that reader must search for barcode with 100% confidence only
                    reader.Settings.MinConfidence = 100;
                    // specify that reader must use barcodes in automatic mode
                    reader.Settings.AutomaticRecognition = true;
                    // specify that reader must search for 1 barcode
                    reader.Settings.ExpectedBarcodes = 1;
    
                    // set the barcode value without checksum
                    writer.Settings.Value = value;
                    // create image with barcode without checksum
                    using (VintasoftBitmap barcodeNoChecksumImage = writer.GetBarcodeAsVintasoftBitmap())
                    {
                        // set the barcode value with checksum
                        writer.Settings.Value = value + GenerateChecksum(value);
                        // create image with barcode with checksum
                        using (VintasoftBitmap barcodeWithMyChecksumImage = writer.GetBarcodeAsVintasoftBitmap())
                        {
                            // specify delegate to a method for barcode verification
                            reader.Settings.VerifyBarcodeMethod = VerifyBarcodeMethod;
    
                            // read barcodes from barcode image without checksum,
                            // barcode reader will not find barcode
                            IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeNoChecksumImage);
                            Console.WriteLine("Scan (NoChecksum):");
                            for (int i = 0; i < infos.Length; i++)
                                Console.WriteLine(infos[i].Value);
    
                            // read barcodes from barcode image with checksum,
                            // barcode reader will find 1 barcode
                            infos = reader.ReadBarcodes(barcodeWithMyChecksumImage);
                            Console.WriteLine("Scan (MyChecksum):");
                            for (int i = 0; i < infos.Length; i++)
                                Console.WriteLine(infos[i].Value);
                        }
                    }
                }
            }
        }
    
        /// <summary>
        /// Generates checksum modulo 1000.
        /// </summary>
        static string GenerateChecksum(string value)
        {
            int checkSum = 0;
            for (int i = 0; i < value.Length; i++)
            {
                checkSum += ((byte)value[i]) * (i + 1);
                checkSum %= 1000;
            }
            // result - [000..999]
            return checkSum.ToString().PadLeft(3, '0');
        }
    
        /// <summary>
        /// Verifies the barcode during the barcode recognition process.
        /// </summary>
        static void VerifyBarcodeMethod(BarcodeReader reader, IBarcodeInfo barcodeInfo)
        {
            if (TestChecksum(barcodeInfo.Value))
                barcodeInfo.Confidence = 100;
            else
                barcodeInfo.Confidence = 0;
        }
    
        /// <summary>
        /// Tests checksum in barcode value.
        /// </summary>
        static bool TestChecksum(string barcodeValue)
        {
            string value = barcodeValue.Substring(0, barcodeValue.Length - 3);
            string readChecksum = barcodeValue.Substring(barcodeValue.Length - 3);
            return readChecksum == GenerateChecksum(value);
        }
    
    }
    
    
    Этот C#/VB.NET код показывает, как удалить штрих-коды с качеством чтения < 0,2.
       
    ''' <summary>
    ''' Verifies the barcode during the barcode recognition process.
    ''' </summary>
    Private Shared Sub VerifyBarcodeMethod(reader As BarcodeReader, barcodeInfo As IBarcodeInfo)   
        If barcodeInfo.ReadingQuality < 0.2 Then   
            barcodeInfo.Confidence = 0   
        End If   
    End Sub   
       
    ' ...
    ' reader.Settings.VerifyBarcodeMethod = VerifyBarcodeMethod;
    ' ...
    
    
    
    /// <summary>
    /// Verifies the barcode during the barcode recognition process.
    /// </summary>
    static void VerifyBarcodeMethod(BarcodeReader reader, IBarcodeInfo barcodeInfo)
    {
        if (barcodeInfo.ReadingQuality < 0.2)
            barcodeInfo.Confidence = 0;
    }
    
    // ...
    // reader.Settings.VerifyBarcodeMethod = VerifyBarcodeMethod;
    // ...
    
    

    Требования

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

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