显示从数据库到pictureBox的图像 [英] show image from database to pictureBox
本文介绍了显示从数据库到pictureBox的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
i想要在图片框中显示保存在我的数据库中的图像。
我该怎么办?
hi
i want to show image that save in my database in a picture box .
How do I do it?
推荐答案
执行datareader并在datareader对象中收集数据
after executing you datareader and gathering data in your datareader object
SqlDataReader dr = callFaceImage.ExecuteReader();
if (dr.hasrows())
{
dr.Read(); //you were missing this W/o this command you cannot read data
byte[] Img =(byte[]) dr["faceImage"];
MemoryStream ms = new MemoryStream(Img);
pictureBox3.Image = Image.FromStream(ms);
pictureBox3.Refresh();
}
CP有规则 [ ^ ]!在提出问题之前,您需要使用SearchBox(位于本页的右上角)。
我发现使用SerachBox的文章很少:
使用Microsoft .NET从SQL Server存储和检索图像 [ ^ ]
在SQL Server中存储或保存图像 [ ^ ]
在SQL Server中存储图像 [ ^ ]
CP has rules[^]! Before you ask a question, you need to use SearchBox (at the right-top corner of this page).
Few articles, which i found using SerachBox:
Storing and Retrieving Images from SQL Server using Microsoft .NET[^]
Store or Save images in SQL Server[^]
Store Images in SQL Server[^]
试用这种方法。
Try this method.
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM ImageUpload WHERE ImgID='100'",cn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string image = Convert.ToString(DateTime.Now.ToFileTime());
byte[] bimage = (byte[])dr["ImgData"];
FileStream fs = new FileStream(image, FileMode.CreateNew, FileAccess.Write);
fs.Write(bimage, 0, bimage.Length - 1);
fs.Close();
pictureBox1.Image = Image.FromFile(image);
}
dr.Close();
cn.Close();
这篇关于显示从数据库到pictureBox的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文