How can I capture a drawing of a panel in winform to bitmap and save it to SQL database?
I also want to display in a datagridview. I tried searching here and tried for hours to do it in all kinds of ways turning it to bitmap through drawtobitmap method and then turning it to a bite array and saving it to database the database shows me 0X89 what does it mean?
And it doesn't show me the image on a datagridview
Can someone just give me a code t开发者_JAVA技巧hat works and I'll improvise thank you very much.
For Saving
Bitmap bmp =new Bitmap(panel1.Width,panel1.Height);
panel1.DrawToBitmap(bmp, panel1.Bounds);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] result = new byte[ms.Length];
ms.Seek(0,System.IO.SeekOrigin.Begin);
ms.Read(result, 0, result.Length);
and save result to your sqlserver table
and to Convert Byte array to image use this
public static Bitmap ConvertBinaryDataToImage(byte[] buffer)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
精彩评论