嗨,我使用下面的代码将图像保存到我的数据库中,
但现在我想知道如何将图片从数据库中获取到 PictureBox
你能帮我么。
private void button1_Click(object sender, EventArgs e)
{
ofdFoto.ShowDialog();
string i = ofdFoto.FileName.ToString();
pbxFoto.ImageLocation = i;
}
private void button2_Click(object sender, EventArgs e)
{
dbConn.Open();
string querys = "INSERT INTO Fruits (Name, Picture) VALUES ('" + txtName.Text + "','" + ImageToByte(pbxFoto.Image) + "')";
OleDbCommand cd = new OleDbCommand(querys, dbConn);
cd.ExecuteNonQuery();
dbConn.Close();
MessageBox.Show("Picture saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}