【发布时间】:2014-09-20 17:15:32
【问题描述】:
我只是想知道是否可以在没有图像路径的情况下将图像保存到数据库中,例如已经分配到图片框中的默认图像。这是我使用的需要图像位置的示例代码。
byte[] imageBt = null;
FileStream fstream = new FileStream(this.txtImage.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBt = br.ReadBytes((int)fstream.Length);
conn.Open();
MySqlCommand command = new MySqlCommand("insert into images(image)values(@IMG)", conn);
command.Parameters.Add(new MySqlParameter("@IMG", imageBt));
reader = command.ExecuteReader();
MessageBox.Show("Saved");
while (reader.Read())
{
}
【问题讨论】:
-
您还想以何种方式接收图像?图像或位图对象?问题中的 Mysql 列也是 Blob 列吗?
-
我想设置一个图像对象是设置在图片框中的默认图像,是的,Mysql 列设置为 Blob .. 谢谢你注意到我的问题 .. xD
-
是的,有可能。有一个不错的example video on youTube,它使用从 PictureBox.Image 提供的内存流。但是这里可能也有几个帖子,向您展示如何,例如 this one.. 看看各种 Blob 大小! Look here!! Blob 默认只有 255 字节
-
感谢您的回答.. 非常感谢