简体   繁体   English

从picturebox默认图像保存图像(来自资源)

[英]Save image from picturebox default image (from resources)

在此输入图像描述

how to save this image into sqlserver, i usually save it from file name but i don't know how to save from resources 如何将此图像保存到sqlserver中,我通常将其从文件名中保存,但我不知道如何从资源中保存

Try this: 尝试这个:

public byte[] WinImage=new byte[0];
MemoryStream stream = new MemoryStream();
PictureBox.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
WinImage=stream.ToArray();

And save it to the table as varbinary(max) . 并将其作为varbinary(max)保存到表中。 To open the image from database: 要从数据库打开图像:

MemoryStream stream = new MemoryStream(byte[] WinImage);
Image RetImage = Image.FromStream(stream);
PictureBox.Image = RetImage;

You can convert image to filestream like this, 您可以像这样将图像转换为文件流,

FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
data = new byte[fs.Length];
fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
fs.Close();

Then you can save the image as byte[] array to your database table where the field datatype is Image . 然后,您可以将图像作为byte[]数组保存到数据库表中,其中字段数据类型为Image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM