我正在尝试使用c#填充Windows应用程序中的图片框。图像路径已保存在数据库中。如何在Windows窗体图片框控件上显示该图像??。
提前致谢
答案 0 :(得分:1)
希望这对你有用:)
if (File.Exists(pathFromYourImage) // Just to check if path is valid
{
PictureBox pb1 = new PictureBox();
pb1.Image = System.Drawing.Image.FromFile(pathFromYourImage);
}
答案 1 :(得分:0)
在C#窗口应用程序中将imagepath
插入mssqlserver
private void button1_Click(object sender, EventArgs e) {
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK) {
pictureBox1.Image = new Bitmap(open.FileName);
string imgpath = open.FileName;
con.Open();
SqlCommand cmd = new SqlCommand("insert into TB_Image values('"+ imgpath+"')", con);
cmd.ExecuteNonQuery();
con.Close();
}
}