Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的数据库是 SQL Server。在那一个照片数据列中。那是varbinary数据类型。如何从该代码中检索原始图像。请提出任何更好的方法
varbinary
问候, Pradeep
VarBinary 是二进制的 - 所以将结果集中的字段转换为byte[]
byte[]
byte[] bytes = (byte[])dataReader["fieldname"];
然后使用 aMemoryStream将字节转换为Image
MemoryStream
Image
public Image BytesToImage(byte[] bytes) { using(MemoryStream ms = new MemoryStream(bytes)) { Image image = Image.FromStream(ms); return image; } }