Groups | Blog | Home
all groups > dotnet drawing api > april 2007 >

dotnet drawing api : tiff image from byte array


Duane
4/17/2007 4:07:49 PM
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




Duane
4/27/2007 1:05:16 PM
Has anyone been able to reproduce this?

AddThis Social Bookmark Button