VintaSoft Barcode .NET SDK v10.0
In This Topic
    Read barcodes from multipage TIFF file in WPF
    In This Topic

    Example: Here is an example that shows how to read barcodes from TIFF file.

    Public Shared Sub ReadBarcodesFromMiltipageTiffFile(filename As String, barcodeTypes As BarcodeType)
            ' open TIFF file
            Dim pageCount As Integer
            Using bitmapStream As Stream = File.Open(filename, FileMode.Open)
                    Dim decoder As New TiffBitmapDecoder(bitmapStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad)
                    Dim tiffImage As BitmapSource
                    pageCount = decoder.Frames.Count
    
                    ' create the barcode reader
                    Using reader As New 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 IBarcodeInfo() = reader.ReadBarcodes(tiffImage)
    
                                    ' output information about barcodes
                                    Console.WriteLine(String.Format("Page {0}: ", i))
                                    If barcodesInfo.Length = 0 Then
                                            Console.WriteLine("No barcodes found.")
                                    Else
                                            For j As Integer = 0 To barcodesInfo.Length - 1
                                                    Console.WriteLine(String.Format("[{0}] {1}", barcodesInfo(j).BarcodeType, barcodesInfo(j).Value))
                                            Next
                                    End If
                            Next
                    End Using
            End Using
    End Sub
                  
    
    public static void ReadBarcodesFromMiltipageTiffFile(string filename, BarcodeType barcodeTypes)
    {
        // open TIFF file
        int pageCount;
        using (Stream bitmapStream = File.Open(filename, FileMode.Open))
        {
            TiffBitmapDecoder decoder = new TiffBitmapDecoder(bitmapStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapSource tiffImage;
            pageCount = decoder.Frames.Count;
    
            // create the barcode reader
            using (BarcodeReader reader = new 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
                    IBarcodeInfo[] barcodesInfo = reader.ReadBarcodes(tiffImage);
    
                    // output information about barcodes
                    Console.WriteLine(string.Format("Page {0}: ", i));
                    if (barcodesInfo.Length == 0)
                    {
                        Console.WriteLine("No barcodes found.");
                    }
                    else
                    {
                        for (int j = 0; j < barcodesInfo.Length; j++)
                            Console.WriteLine(string.Format("[{0}] {1}", barcodesInfo[j].BarcodeType,
                                                                         barcodesInfo[j].Value));
                    }
                }
            }
        }
    }