简体   繁体   English

字节数组到IIS6上的图像

[英]Byte array to Image on IIS6

REWORDING THE QUESTION: 改写这个问题:

I have a large number of .tif files, most of which (if not all) have the following definitions: 我有大量的.tif文件,其中大多数(如果不是全部)具有以下定义:

  • Bit depth: 1 位深:1
  • Compression: CCITT T.6 (Group 4) 压缩:CCITT T.6(第4组)

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. 然后,我将这些字节数组保存在SQL Server 12 DB的varbinary列中。

Now, I am making an MVC2 web page to view these .tif files. 现在,我正在制作一个MVC2网页来查看这些.tif文件。 The process is then supposed to be: 然后,该过程应为:

  • load the byte array 加载字节数组
  • the convert it to Image 将其转换为Image
  • select a page in the .tif 在.tif中选择一个页面
  • convert that page to a Jpeg 将该页面转换为Jpeg
  • send the page to the browser 将页面发送到浏览器

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: 将项目安装到目标IIS(当前为6,我已经打开7.5的请求)后,该过程在以下行失败:

[... 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. 现在,我收到的字节数组是不是错误的-它是从字面上 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. 我现在不确定原始图像的像素格式是什么,尽管从字节数组转换回Image后它是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. 仅供参考-如果可能,切换到IIS7可以完全解决问题。

I still haven't figured this out on IIS6... and spent another full workday hammering away at it... to no avail. 我仍然没有在IIS6上弄清楚这个问题,并花了另一个完整的工作日对其进行研究……无济于事。 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. 我相信这与MIME类型处理有关,是IIS7中DLL的一些附加功能,也许是GDI + ...我真的不知道。 But, if anyone else runs into this problem - upgrade to IIS7 and save yourself the hassle. 但是,如果还有其他人遇到此问题- 升级到IIS7并省去麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM