Get Image Count from Tiff's

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
I have the below code that gets the image count from a Tiff file.... However, I need it to search a bunch of Tiff's and in subfolders. Does anyone know how to make it where it counts all the Tiff's in a directory instead of just one tiff?

VB.NET:
  Dim img As Image = Image.FromFile(filename)
        Dim numpages As Integer = img.GetFrameCount(Imaging.FrameDimension.Page)
        Label1.Text = numpages
        img.Dispose()

Thanks for your help
 
You really did provide a poor title for this thread. I've ignored it several times because I thought that it was on a subject that I didn't know much. Now that I've opened it I see that it's not about getting the image count from a TIFF at all, because you already know how to do that. What it's actually about is getting the files in folder. I suggest that you think a bit harder in future about the actual subject of the question you're asking and provide a more accurate title.

Anyway, the Directory.GetFiles method will return a String array containing the path of each file in a specified folder. You can then use a For Each loop to enumerate that array and put the code you already have inside it. Just note that you will have to change that line that displays the count on a Label because that will end up just showing the last count. Exactly what you need to do depends on exactly what behaviour you want.

Also, the preferred way to create and then dispose a short-lived object is with the Using statement, e.g.
Using img As Image = Image.FromFile(filename)
    Dim numpages As Integer = img.GetFrameCount(Imaging.FrameDimension.Page)

    Label1.Text = numpages
End Using
 
Back
Top