如何将type'string'转换为system.drawing.image

时间:2015-08-07 07:34:16

标签: c# database database-design c#-3.0

我只想将数据库中的图像放到图片框中,就像其他数据一样。我怎么能这样做?

private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
      //shows the data on fields if click on the entries 
      //on sequence in which the query is 

      IDtxt.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
      NAMEtxt.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
      F_Nametxt.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
      BLOODc_box .Text  = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
      CNICtxt .Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();

      GENDERc_box .Text  = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
      CONTACTtxt.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
      JOBtitleText.Text = dataGridView1.SelectedRows[0].Cells[7].Value.ToString();
      SALARYtxt.Text = dataGridView1.SelectedRows[0].Cells[8].Value.ToString();
      ADDRESStxt.Text = dataGridView1.SelectedRows[0].Cells[9].Value.ToString();
      AGEtxt .Text  = dataGridView1.SelectedRows[0].Cells[10].Value.ToString();
      pictureBox1 .Image   =  dataGridView1.SelectedRows[0].Cells[11].Value.ToString();

}

2 个答案:

答案 0 :(得分:1)

如果你有base64字符串,那么试试这个

var image = GetImage("yourBase64String");

public Image GetImage(string value)
{        
    byte[] bytes = Convert.FromBase64String(value);
    Image image;
    using (MemoryStream ms = new MemoryStream(bytes))
    {
        image = Image.FromStream(ms);
    }
    return image;
}

答案 1 :(得分:0)

'Picture 
Dim myFile As String = gvAutok.SelectedRows(0).Cells(9).Value
Dim Image As Image = Image.FromFile(myFile)
picBox.Image = Image