C#中的图片框图像 [英] picturebox image in c#
本文介绍了C#中的图片框图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图像从数据块加载到图片框.我使用以下代码将它们加载到我的图片中.我写了一些代码,但我不知道继续执行这些代码应该怎么做.
任何帮助将不胜感激.
提前谢谢.
i''m trying to load images from databes to the picturebox. i use these following codes in order to load them to my picture. i wrote some codes but i don''t know what should i do for continuing this codes.
Any help will be appreciated.
Thanks in advance.
private void button1_Click(object sender, EventArgs e)
{
sql = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Test;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = sql;
cmd.CommandText = ("select Image from Entry where EntryID =@EntryID");
cmd.Parameters.AddWithValue("@EntryID", Convert.ToInt32(textBox1.Text));
}
推荐答案
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand com = new SqlCommand("SELECT Image FROM Entry WHERE EntryID =@EntryID", con))
{
cmd.Parameters.AddWithValue("@EntryID", Convert.ToInt32(textBox1.Text));
using (SqlDataReader reader = com.ExecuteReader())
{
if (reader.Read())
{
byte[] bytes = (byte[]) reader["Image"];
MemoryStream ms = new MemoryStream(bytes);
Image img = Image.FromStream(ms);
myPictureBox.Image = img;
}
}
}
}
这篇关于C#中的图片框图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文