c# - 将 Stream 转换为 Image 时参数无效异常

标签 c# database image stream

我正在处理 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.htmlhttp://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/

相关文章:

php - 在 php 中选择的多个复选框的数据未存储在数据库中

HTML/CSS 使 3 个图像在线响应且设计良好

java - Java获取图像宽度和高度

image - 适用于 Instagram 的 ffmpeg 缩放图像 (640x640)

c# - ServiceStack:解析未知类型的服务

MySQL 数据库连接与 Visual Studio 2013 预览版

c# - WPF 数据网格中的内存泄漏问题

database - 如何像在dolphindb中一样在clickhouse中实现 `pivot`

c# - 我无法使用 C# 使用 Facebook SDK 5.1 检索我的群组

c# - OPPO R7g 上的 Xamarin 调试崩溃