Usama Haleem
Usama Haleem

Reputation: 39

how to convert type'string' into system.drawing.image

I just want to get the image from database into a picture box as like other data is. How can I do that?

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();

}

Upvotes: 1

Views: 5595

Answers (2)

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

Upvotes: 0

M. Nasir Javaid
M. Nasir Javaid

Reputation: 5990

If you have base64 string then try this

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;
}

Upvotes: 2

Related Questions