REWORDING THE QUESTION:
I have a large number of .tif files, most of which (if not all) have the following definitions:
Some are multipage, some aren't.
I loaded them using the following:
private byte[] LoadArchivedFile()
{
FileStream file = File.Open(fileAddress, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] fileByteArray = ReadFully(file, 0);
return fileByteArray;
}
I then saved these byte arrays in an SQL Server 12 DB, varbinary column.
Now, I am making an MVC2 web page to view these .tif files. The process is then supposed to be:
Image
In the development environment everything works perfectly. Once I install the project on the target IIS (currently 6, I've opened a request for 7.5), the process fails on the following line:
[... load byte array from DB]
byte[] imageBinary = (byte[])results.fileBinary;
using(MemoryStream ms = new MemoryStream(imageBinary))
{
Image image = Image.FromStream(ms); <---- FAILS HERE
[...]
}
The stacktrace:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at [MyCode]
Now, the byte array that I receive is not faulty - it is literally the same data from the DB. I even compared several bytes, overall length... anyway, it's the same source. This isn't where the fault lies.
I found another question with a similar (though not exactly the same) problem. There, the matter of bit depth, pixel format, compression and codecs. I am unsure at the moment what the pixel format of the original images is, though after conversion from byte array back to Image it is Format1bppIndexed.
I am pretty much at a loss... Is the problem with a missing codec on the target machine? Is there something I need to do before uploading the image binary to the DB?
FYI - if possible, a switch to IIS7 solves the problem completely.
I still haven't figured this out on IIS6... and spent another full workday hammering away at it... to no avail. I believe it to be something with MIME-type handling, some addition to a DLL in IIS7, maybe the GDI+... I don't really know. But, if anyone else runs into this problem - upgrade to IIS7 and save yourself the hassle.