VintaSoft Barcode .NET SDK 15.0: Documentation for .NET developer
In This Topic
    Read barcodes from multipage TIFF file in WPF
    In This Topic
    Here is C#/VB.NET code that demonstrates how to load bitmaps from multipage TIFF file using WPF and recognize barcodes in loaded bitmaps.

    /// <summary>
    /// Reads barcodes from an multipage TIFF file in WPF.
    /// </summary>
    /// <param name="filename">A path to a multipage TIFF file.</param>
    /// <param name="barcodeTypes">A types of barcodes to recognize.</param>
    public static void ReadBarcodesFromMiltipageTiffFile(string filename, Vintasoft.Barcode.BarcodeType barcodeTypes)
    {
        // open TIFF file
        using (System.IO.Stream bitmapStream = System.IO.File.Open(filename, System.IO.FileMode.Open))
        {
            System.Windows.Media.Imaging.TiffBitmapDecoder decoder =
                new System.Windows.Media.Imaging.TiffBitmapDecoder(
                    bitmapStream,
                    System.Windows.Media.Imaging.BitmapCreateOptions.None,
                    System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
            System.Windows.Media.Imaging.BitmapSource tiffImage;
            int pageCount = decoder.Frames.Count;
    
            // create the barcode reader
            using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
            {
                // set barcode reader settings
                reader.Settings.ScanBarcodeTypes = barcodeTypes;
    
                // for each page
                for (int i = 0; i < pageCount; i++)
                {
                    // select a page
                    tiffImage = decoder.Frames[i];
    
                    // read barcodes from image
                    Vintasoft.Barcode.IBarcodeInfo[] barcodesInfo = Vintasoft.Barcode.WpfExtensions.ReadBarcodes(reader, tiffImage);
    
                    // output information about barcodes
                    System.Console.WriteLine(string.Format("Page {0}: ", i));
                    if (barcodesInfo.Length == 0)
                    {
                        System.Console.WriteLine("No barcodes found.");
                    }
                    else
                    {
                        for (int j = 0; j < barcodesInfo.Length; j++)
                            System.Console.WriteLine(string.Format("[{0}] {1}", barcodesInfo[j].BarcodeType,
                                                                         barcodesInfo[j].Value));
                    }
                }
            }
        }
    }       
    
    ''' <summary>
    ''' Reads barcodes from an multipage TIFF file in WPF.
    ''' </summary>
    ''' <param name="filename">A path to a multipage TIFF file.</param>
    ''' <param name="barcodeTypes">A types of barcodes to recognize.</param>
    Public Shared Sub ReadBarcodesFromMiltipageTiffFile(filename As String, barcodeTypes As Vintasoft.Barcode.BarcodeType)
        ' open TIFF file
        Using bitmapStream As System.IO.Stream = System.IO.File.Open(filename, System.IO.FileMode.Open)
            Dim decoder As New System.Windows.Media.Imaging.TiffBitmapDecoder(bitmapStream, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad)
            Dim tiffImage As System.Windows.Media.Imaging.BitmapSource
            Dim pageCount As Integer = decoder.Frames.Count
    
            ' create the barcode reader
            Using reader As New Vintasoft.Barcode.BarcodeReader()
                ' set barcode reader settings
                reader.Settings.ScanBarcodeTypes = barcodeTypes
    
                ' for each page
                For i As Integer = 0 To pageCount - 1
                    ' select a page
                    tiffImage = decoder.Frames(i)
    
                    ' read barcodes from image
                    Dim barcodesInfo As Vintasoft.Barcode.IBarcodeInfo() = Vintasoft.Barcode.WpfExtensions.ReadBarcodes(reader, tiffImage)
    
                    ' output information about barcodes
                    System.Console.WriteLine(String.Format("Page {0}: ", i))
                    If barcodesInfo.Length = 0 Then
                        System.Console.WriteLine("No barcodes found.")
                    Else
                        For j As Integer = 0 To barcodesInfo.Length - 1
                            System.Console.WriteLine(String.Format("[{0}] {1}", barcodesInfo(j).BarcodeType, barcodesInfo(j).Value))
                        Next
                    End If
                Next
            End Using
        End Using
    End Sub