在gridview控件中显示数据库中的图像期间,发生以下错误:Parameter is not valid
以下代码显示图像:
var id = Convert.ToString(user_id);
var category = (from data in db.Register1_db
where (data.User_ID == id)
select ( data.Student_Photo));
int len = category.First().Length;
// Output the binary data
// But first we need to strip out the OLE header
int OleHeaderLength = 78;
int strippedImageLength = len - OleHeaderLength;
byte[] imagdata = new byte[strippedImageLength];
Array.Copy(category.First().ToArray(), OleHeaderLength, imagdata, 0, strippedImageLength);
if ((imagdata) != null)
{
MemoryStream m = new MemoryStream(imagdata);
//error occurred
System.Drawing.Image image = System.Drawing.Image.FromStream(m);
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}