[英]How to save image in SQL image type column from picturebox without mentioning pics url?
我有一个图片picturebox
,现在按下鼠标按钮时便会绘制自定义图像,我想将该图像保存在SQL的image type column
。
我确实搜索了保存,但是没有什么可以将图片从picturebox保存到没有url的sql图像类型列中。
您可能可以使用此解决方案 。 您首先必须将图片框图像保存为jpeg。
byte[] image = File.ReadAllBytes("D:\\11.jpg");
编辑:
//without saving the image to a physical file
MemoryStream stream=new MemoryStream();
pictureBox1.Image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic=stream.ToArray();
SqlCommand sqlCommand = new SqlCommand("INSERT INTO imageTest (pic_id, pic) VALUES (1, @Image)", yourConnectionReference);
sqlCommand.Parameters.AddWithValue("@Image", image);
sqlCommand.ExecuteNonQuery();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.