我正在处理 Northwind.sdf 数据库,并尝试通过以下代码从员工表中保存员工的照片: 我得到了字节[]。 row 是 DataTable 中的 DataRow。
byte[] b = (byte[])row["Photo"];
MemoryStream str = new MemoryStream(b);
Image im = Image.FromStream(str);
im.Save("Fuller.png");
在尝试将流转换为图像时,我收到“参数无效”异常。
最佳答案
根据这些文章:http://www.akadia.com/services/dotnet_load_blob.html和 http://www.eggheadcafe.com/articles/20050911.asp “Northwind 员工表是从 MS Access 设计的,它需要 78 字节的 OLE header ”。您必须省略 MemoryStream 中的前 78 个。
MemoryStream str = new MemoryStream();
int offset = 78;
str.Write(b, offset, b.Length - offset);
Image im = Image.FromStream(str);
关于c# - 将 Stream 转换为 Image 时参数无效异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17355474/