我有一个数据库,其中包含一个名为的表Products
,其中包含产品的图片。
要将图像存储在内存中
public byte[] Picture
所以在我的数据库中它是一个 varbinary 类型(自动转换)所以,我想做的是在 pictureBox1.Image 中显示来自数据库的图像。像这样的东西:
var q_pic = from p in context.Products
where p.ID == value // Id of product that i want
select new
{
p.Picture
};
现在
picutreBox1.Image = ??
原因
pictureBox1.Image = q_pic // doeasn't work
我试过这个:
var bytes = from p in context.Products
where p.ID == value // Id of product that i want
select p.Picture;
if (bytes != null)
{
using (var ms = new MemoryStream(bytes))
{
using (var image = Image.FromStream(ms))
{
pictureBox1.Image = (Image)image.Clone();
}
}
}
得到这个
Error 1 The best overloaded method match for 'System.IO.MemoryStream.MemoryStream(byte[])' has some invalid arguments
Error 2 Argument 1: cannot convert from 'System.Linq.IQueryable<byte[]>' to 'byte[]'