I'm having problems getting the page count of a tiff image from a multi page tiff that was saved to a byte array and then loaded into a bitmap object using image.FromStream. When the following code is ran against a tiff file containing 2 pages the first line written to the console will state: "image contains 2 pages" while the second line will state: "image contains 1 pages". The code below uses a sample two page tiff named d:\2page.tiff. Please substitute a valid 2 page tiff when testing on your system. Any help would be much appreciated. --Duane Imports System.Drawing Module Module1 Sub Main() Dim bmp As Bitmap = Nothing '-- open a tiff that contains 2 pages bmp = New Bitmap("D:\2page.tiff") '-- save the image to a memory stream Dim ms As New IO.MemoryStream bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff) '-- write the number of pages in the image to the console Console.WriteLine("image contains {0} pages", _ bmp.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page).ToString) '-- read the stream into the byte array Dim data() As Byte = ms.ToArray '-- dispose of resources bmp.Dispose() ms.Dispose() bmp = Nothing ms = Nothing '-- initialize the memory stream with the data in the byte array ms = New IO.MemoryStream(data) '-- create a bitmap from the data in the memory stream bmp = CType(Image.FromStream(ms), Bitmap) '-- write the number of pages in the image to the console Console.WriteLine("image contains {0} pages", _ bmp.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page).ToString) '-- dispose of resources bmp.Dispose() ms.Dispose() bmp = Nothing ms = Nothing Console.ReadLine() End Sub End Module
Has anyone been able to reproduce this?
Don't see what you're looking for? Try a search.
|