VintaSoft Barcode .NET SDK v10.0
In This Topic
    Read barcodes from System.Windows.Media.Imaging.BitmapSource object in WPF
    In This Topic

    Example: Here is an example that shows how to read barcodes from System.Windows.Media.Imaging.BitmapSource object.

    Public Shared Sub ReadBarcodesFromBitmapSource(barcodeImage As BitmapSource)
            ' 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
    
                    ' use Automatic Recognition
                    reader.Settings.AutomaticRecognition = True
    
                    ' read barcodes from image
                    Dim infos As IBarcodeInfo() = reader.ReadBarcodes(barcodeImage)
    
                    ' if barcodes are not detected
                    If infos.Length = 0 Then
                            Console.WriteLine("No barcodes found.")
                    Else
                            ' if barcodes are detected
                            ' get information about extracted barcodes
    
                            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 + 1, info.BarcodeType))
                                    Console.WriteLine(String.Format("Value:      {0}", info.Value))
                                    Console.WriteLine(String.Format("Region:     {0}", info.Region))
                                    Console.WriteLine()
                            Next
                    End If
            End Using
    End Sub
                  
    
    public static void ReadBarcodesFromBitmapSource(BitmapSource barcodeImage)
    {
        // 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;
    
            // use Automatic Recognition
            reader.Settings.AutomaticRecognition = true;
    
            // read barcodes from image
            IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeImage);
    
            // if barcodes are not detected
            if (infos.Length == 0)
            {
                Console.WriteLine("No barcodes found.");
            }
            // if barcodes are detected
            else
            {
                // get information about extracted barcodes
    
                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 + 1, info.BarcodeType));
                    Console.WriteLine(string.Format("Value:      {0}", info.Value));
                    Console.WriteLine(string.Format("Region:     {0}", info.Region));
                    Console.WriteLine();
                }
            }
        }
    }