开发者

Image.FromStream don't work the same way on my new windows installation

I've got this test that used to works on my old machine. (Windows Vista Ultimate 32-bit)

开发者_如何学C
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);
    }
}

On my new machine (Windows 7 64-bit) it doesn't work anymore.

I get this exception:

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()

If I instead try with this it works...

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
    };

Why doesn't this work on my new machine?


Have you tried adding an extra 0 byte at the end? I have a good feeling about that!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜