VintaSoft Barcode .NET SDK v10.0
Vintasoft.WpfBarcode Namespace / ReaderSettings Class / VerifyBarcodeMethod Property
Example




In This Topic
    VerifyBarcodeMethod Property (ReaderSettings)
    In This Topic
    Gets or sets method that verifies the information about barcode found by barcode reader.
    Syntax
    'Declaration
     
    <XmlIgnoreAttribute()>
    Public Property VerifyBarcodeMethod As VerifyBarcodeDelegate
    'Usage
     
    Dim instance As ReaderSettings
    Dim value As VerifyBarcodeDelegate
     
    instance.VerifyBarcodeMethod = value
     
    value = instance.VerifyBarcodeMethod
    [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);
    }
    Remarks
    Method that verifies the information about barcode found by barcode reader executes every time when the "barcode" is found by the barcode reader.

    Application can analyze information about found barcode and change Confidence if this is necessary.

    Method that verifies the information about barcode found can be used in automatic or iteration recognition mode and increase quality of recognition.
    Example
    This example generates Code 39 barcode with user-defined base 1000 cheksum, and read it using check barcode checksum in verify barcode method. This example shows how to remove barcodes with reading quality<0.2.
    Imports System.Windows.Media.Imaging   
       
    Imports Vintasoft.WpfBarcode   
       
    ''' <summary>   
    ''' Test that shows how to set a delegate for barcode verification and   
    ''' verify found barcode 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   
    		Dim 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   
    			Dim barcodeNoChecksumImage As BitmapSource = writer.GetBarcodeAsBitmapSource()   
       
    			' set the barcode value with checksum   
    			writer.Settings.Value = value & GenerateChecksum(value)   
    			' create image with barcode with checksum   
    			Dim barcodeWithMyChecksumImage As BitmapSource = writer.GetBarcodeAsBitmapSource()   
       
    			' 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 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 the 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 System.Windows.Media.Imaging;
                
    using Vintasoft.WpfBarcode;
                
    /// <summary>
    /// Test that shows how to set a delegate for barcode verification and
    /// verify found barcode during the barcode recognition process.
    /// </summary>
    class UserDefinedChecksumExample
    {
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Run()
        {
            string value = "1234567890AbC";
                
            // create the barcode writer
            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
                BitmapSource barcodeNoChecksumImage = writer.GetBarcodeAsBitmapSource();
                
                // set the barcode value with checksum
                writer.Settings.Value = value + GenerateChecksum(value);
                // create image with barcode with checksum
                BitmapSource barcodeWithMyChecksumImage = writer.GetBarcodeAsBitmapSource();
                
                // 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 the 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);
        }
                
    }
    ''' <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;
    // ...
    Requirements

    Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also