How to convert byte array into a image?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GauravRashinkar
    New Member
    • Nov 2010
    • 1

    #1

    How to convert byte array into a image?

    How to convert byte array into a image?

    Code:
    Byte[] photo = Convert.FromBase64String(value);
                    //System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                    //Byte[] photo = encoding.GetBytes(value);
                    //old 1
                    MemoryStream ms = new MemoryStream(photo, 0, photo.Length);
                    ms.Position = 0;
                    ms.Write(photo, 0, photo.Length);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);// this line giving exception parameter not valid
    
                    image.Save(@"C:\MyImage2.jpg");
    Last edited by Frinavale; Aug 4 '17, 05:59 PM.
  • lal ramesh
    New Member
    • Nov 2010
    • 1

    #2
    Code:
     try
                {
                    //Get image data from gridview column.
                    byte[] imageData = (byte[])dataGridView1.Rows[e.RowIndex].Cells["ImageData"].Value;
    
                    //Initialize image variable
                    Image newImage;
                    //Read image data into a memory stream
                    using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length))
                    {
                        ms.Write(imageData, 0, imageData.Length);
    
                        //Set image variable value using memory stream.
                        newImage = Image.FromStream(ms, true);
                    }
    
                    //set picture
                    pictureBox1.Image = newImage;
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    that code will be help you.
    thanks.
    Last edited by Niheel; May 16 '13, 06:48 AM. Reason: no link signatures in forum

    Comment

    • wubuer
      New Member
      • Jul 2017
      • 1

      #3
      you can try to convert byte array pdf to jpg in c# using this control

      Comment

      Working...