Problem loading TIF files

deejross

Member
Joined
May 10, 2006
Messages
8
Programming Experience
3-5
I'm working on a document managment application which uses TIF as it's main format. There are several files that load fine in any other program except mine. Here is the code I had originally:

VB.NET:
Dim img as Image
img = Image.FromFile(filename)

When it gets to the second line, it would give me an Out of Memory exception. Then after Googling the problem, I came up with the solution:

VB.NET:
Dim fStream as new FileStream(filename, FileMode.Open)
img = Image.FromStream(filename)

Which gave me the exception "Parameter is not valid." Again, I Googled the problem. This time though, the results of the search came back with people having problems loading images from a byte array. So again, I rewrote my code:

VB.NET:
Dim fStream as new FileStream(filename, FileMode.Open)
Dim memStream as new MemoryStream
Dim bytes(fStream.Length) as Byte

fStream.Read(bytes, 0, fStream.Length)
memStream.Write(bytes, 0, bytes.Length)
memStream.Position = 0

img = New Bitmap(memStream)

This also failed with the same error. I have tried many times interchanging between:

VB.NET:
img = Image.FromFile(filename)
img = Image.FromStream(fStream)
img = New Bitmap(filename)
img = New Bitmap(fStream)

None have worked. After searching Google and this site again, I kept coming up with the answer, "you need to reset your memory stream to position=0 before loading the image". Which I already tried. I thought maybe the TIF files were too big for .NET to handle, but other applications don't seem to have a problem with them. The average filesize is about 1MB. Dimensions are around 1800 x 2200. Most are single page TIF files.

I am developing this application in Visual Studio 2005, in VB.NET. I have compiled and run this on other machines which are also showing this error.

Thanks in advance.
 
I found the solution on another forum. It turns out that some TIF files are formatted differently so that only the Microsoft Fax Viewer can view them. Even Photoshop won't open these TIF files.
 
Back
Top