我花了2个月的时间尝试将图像插入数据库并再次检索它!我已成功将图像插入数据库,但当我尝试将其检索到图片框时,我得到了这个例外 顺便说一句我正在使用扫描仪所以我不需要浏览一个文件我只想将它从picturebox插入数据库并再次将其检索到picturebox
插入步骤
// ---------------
MemoryStream ms = new MemoryStream();
PBoxGuestImage.Image.Save(ms, ImageFormat.Jpeg);
Byte[] PicArray = new Byte[ms.Length];
ms.Position = 0;
ms.Read(PicArray, 0, PicArray.Length);
CMD.CommandText = "Insert Into TestTable(TestImage) Values (@ParTestImage)"
CMD.Parameters.AddWithValue("@ParTestImage", PicArray);
//---------------
//this works great
//Retrieve Step
Image NewImage;
byte[] content = (byte[])TestReader["TestImage"];
TestPictureBox.Image = null;
using (MemoryStream stream = new MemoryStream(content, 0, content.Length))
{
stream.Write(content, 0, content.Length);
NewImage = Image.FromStream(stream, true); //at this line i get the exception
}
TestPictureBox.Image = NewImage;
无论如何都要解决这个问题?
感谢。