title: Byte array to image conversion
body: <p>I want to convert a byte array to an image.</p>
  
  <p>This is my database code from where I get the byte array:</p>
  
  <pre><code>public void Get_Finger_print()
  {
      try
      {
          using (SqlConnection thisConnection = new SqlConnection(@"Data Source=" + System.Environment.MachineName + "\\SQLEXPRESS;Initial Catalog=Image_Scanning;Integrated Security=SSPI "))
          {
              thisConnection.Open();
              string query = "select pic from Image_tbl";// where Name='" + name + "'";
              SqlCommand cmd = new SqlCommand(query, thisConnection);
              byte[] image =(byte[]) cmd.ExecuteScalar();
              Image newImage = byteArrayToImage(image);
              Picture.Image = newImage;
              //return image;
          }
      }
      catch (Exception) { }
      //return null;
  }
  </code></pre>
  
  <p>My conversion code:</p>
  
  <pre><code>public Image byteArrayToImage(byte[] byteArrayIn)
  {
      try
      {
          MemoryStream ms = new MemoryStream(byteArrayIn,0,byteArrayIn.Length);
          ms.Write(byteArrayIn, 0, byteArrayIn.Length);
          returnImage = Image.FromStream(ms,true);//Exception occurs here
      }
      catch { }
      return returnImage;
  }
  </code></pre>
  
  <p>When I reach the line with a comment, the following exception occurs: <code>Parameter is not valid.</code></p>
  
  <p>How can I fix whatever is causing this exception?</p>