Display image in grid view

sederisa

New Member
During display of an image from database in the gridview control, the following error occurred: \[code\]Parameter is not valid\[/code\]The following code displays the image:\[code\] 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 = http://stackoverflow.com/questions/12774151/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); }\[/code\]
 
Back
Top