Image.FromStream在我的新Windows安装上的工作方式不同

时间:2011-01-31 08:13:26

标签: c# .net windows .net-3.5 system.drawing

我已经有了这个曾经在我的旧机器上运行的测试。 (Windows Vista Ultimate 32位)

private static readonly byte[] TEST_BMP = new byte[]
    {
        0x42, 0x4D, 0x7E, 0, 0, 0, 0, 0, 0, 0, 0x76, 0, 0, 0, 0x28, 0, 0, 0, 0x2,
        0, 0, 0, 0x2, 0, 0, 0, 0x1, 0, 0x4, 0, 0, 0, 0, 0, 0x8, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0x80,
        0, 0, 0, 0x80, 0x80, 0, 0x80, 0, 0, 0, 0x80, 0, 0x80, 0, 0x80, 0x80, 0, 0,
        0x80, 0x80, 0x80, 0, 0xC0, 0xC0, 0xC0, 0, 0, 0, 0xFF, 0, 0, 0xFF, 0, 0, 0,
        0xFF, 0xFF, 0, 0xFF, 0, 0, 0, 0xFF, 0, 0xFF, 0, 0xFF, 0xFF, 0, 0, 0xFF,
        0xFF, 0xFF, 0, 0x40, 0, 0, 0, 0xF9, 0, 0
    };

[Test]
public void Can_get_Image_from_BMP_Stream()
{
    using (var memStream = new MemoryStream(TEST_BMP))
    {
        Image image = Image.FromStream(memStream);
        Assert.NotNull(image);
    }
}

在我的新机器(Windows 7 64位)上,它不再起作用了。

我得到了这个例外:

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 Litium.Framework.Image.Test.ImageManagerTests.Can_get_Image_from_BMP_Stream()

如果我试着用它来运作......

private static readonly byte[] TEST_GIF = new byte[]
    {
        0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x2, 0, 0x2, 0, 0x11, 0, 0, 0x2C, 0, 0
        , 0, 0, 0x2, 0, 0x2, 0, 0xA1, 0xFF, 0, 0, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0,
        0x80, 0x2, 0x3, 0xC, 0x26, 0x5, 0, 0x3B
    };

为什么这不适用于我的新机器?

1 个答案:

答案 0 :(得分:1)

你有没有尝试在最后添加一个额外的0字节?我对此感觉很好!