1
嗨一個PictureBox我用下面的代碼將圖像保存到我的數據庫,獲取從MS Access中的圖片在C#
,但現在我想知道我可以從數據庫中獲取的圖片到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[]));
}
我的代碼將圖像從字節轉換爲圖像,但我怎樣才能得到它變成一個PictureBox 。 – ArnoDT 2012-08-01 13:48:07
我更新了我的答案 – Ria 2012-08-01 15:31:45
謝謝,我如何從我的數據庫中獲取圖片 – ArnoDT 2012-08-01 16:07:28