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

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

    Public Shared Sub ReadBarcodesFromMiltipageTiffFile(filename As String, barcodeType As BarcodeType)
            ' open TIFF file
            Using tiffImage As Image = Image.FromFile(filename)
                    Dim index As Guid = tiffImage.FrameDimensionsList(0)
                    Dim dimension As New FrameDimension(index)
                    Dim pageCount As Integer = tiffImage.GetFrameCount(dimension)
    
                    ' create the barcode reader
                    Using reader As New BarcodeReader()
                            ' set barcode reader settings
                            reader.Settings.ScanBarcodeTypes = barcodeType
    
                            ' read barcodes from all pages
                            For i As Integer = 0 To pageCount - 1
                                    ' select a page
                                    tiffImage.SelectActiveFrame(dimension, i)
    
                                    ' read barcodes
                                    Dim barcodesInfo As IBarcodeInfo() = reader.ReadBarcodes(tiffImage)
    
                                    ' output information about barcodes
                                    Console.WriteLine(String.Format("Page {0}: ", i))
                                    ' if barcodes are not detected
                                    If barcodesInfo.Length = 0 Then
                                            Console.WriteLine("No barcodes found.")
                                    Else
                                            ' if barcodes are detected
                                            ' get information about extracted barcodes
    
                                            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 barcodeType)
    {
        // open TIFF file
        using (Image tiffImage = Image.FromFile(filename))
        {
            Guid index = tiffImage.FrameDimensionsList[0];
            FrameDimension dimension = new FrameDimension(index);
            int pageCount = tiffImage.GetFrameCount(dimension);
    
            // create the barcode reader
            using (BarcodeReader reader = new BarcodeReader())
            {
                // set barcode reader settings
                reader.Settings.ScanBarcodeTypes = barcodeType;
    
                // read barcodes from all pages
                for (int i = 0; i < pageCount; i++)
                {
                    // select a page
                    tiffImage.SelectActiveFrame(dimension, i);
    
                    // read barcodes
                    IBarcodeInfo[] barcodesInfo = reader.ReadBarcodes(tiffImage);
    
                    // output information about barcodes
                    Console.WriteLine(string.Format("Page {0}: ", i));
                    // if barcodes are not detected
                    if (barcodesInfo.Length == 0)
                    {
                        Console.WriteLine("No barcodes found.");
                    }
                    // if barcodes are detected
                    else
                    {
                        // get information about extracted barcodes
    
                        for (int j = 0; j < barcodesInfo.Length; j++)
                            Console.WriteLine(string.Format("[{0}] {1}", barcodesInfo[j].BarcodeType,
                                                                         barcodesInfo[j].Value));
                    }
                }
            }
        }
    }