2012-08-01 2 views
1

안녕에의 PictureBox에 MS 액세스에서 사진을 얻기하지만 지금 내가에 데이터베이스에서 사진을 얻을 수있는 방법을 알고 싶어요 PictureBox은 내가 아래의 코드는, 내 데이터베이스에</p> <p>을 이미지를 저장하는 데 사용한 C#을

도와주세요.

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[])); 
} 

답변

0
private void button1_Click(object sender, EventArgs e) 
    { 
     PictureBox p =new PictureBox(); 
     p.ImageLocation = ofdFoto.FileName.ToString(); 
     p.Location = new Point(100, 100); 
     this.Controls.Add(p); 
    } 

이 당신을 도움이된다면 참조하십시오! PictureBox.Image 속성에

public static Bitmap BytesToBitmap(byte[] byteArray) 
{ 
    using (var ms = new MemoryStream(byteArray)) 
    { 
     var img = (Bitmap)Image.FromStream(ms); 
     return img; 
    } 
} 

및 설정 :

0

이 코드를 시도

pictureBox1.Image = BytesToBitmap(byteArray); 
+0

나는 이미지 바이트에서 이미지를 변환하는 코드를 가지고 있지만, 방법은 내가의 PictureBox에 그것을 얻을 수 . – ArnoDT

+0

답안을 – Ria

+0

업데이트했습니다. 내 데이터베이스에서 어떻게 사진을 얻을 수 있습니까? – ArnoDT

관련 문제