问题描述
我使用qrcode显示图像,但我不知道如何在sql server中保存它。
我尝试了什么:
这是我从qr到picturebox显示图像的方式:
byte [] imageBytes = dr [SmStockImage] as byte [];
if(imageBytes!= null)
{
using(var stream = new MemoryStream (imageBytes))
pbxBagImg.Image = Image.FromStream(stream);
}
Im using a qrcode to display image but i don't know how to save it in sql server.
What I have tried:
this is how i display image from qr to picturebox:
byte[] imageBytes = dr["SmStockImage"] as byte[];
if (imageBytes != null)
{
using (var stream = new MemoryStream(imageBytes))
pbxBagImg.Image = Image.FromStream(stream);
}
推荐答案
byte[] bytes;
using (var stream = new MemoryStream())
{
image.Save(stream, ImageFormat.Jpeg);
stream.Flush();
bytes = stream.ToArray();
}
假定图片
是您之前使用要保存的图像初始化的变量。
此后,您只需传递 bytes 作为
SQL INSERT
命令的参数。
This assumes image
is a variable you have previously initialized with the image you want to save.
After this, you just pass the value of bytes
as a parameter into your SQL INSERT
command.
这篇关于C#如何在不使用文件对话框的情况下将图像保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!