System.ArgumentException: Parameter is not valid
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/629955/parameter-not-valid-exception-loading-system-drawing-image">&ldquo;Parameter not valid&rdquo; exception loading System.Drawing.Image</a>  </p>
</blockquote>



<p>I am inserting a image in the DB. </p>

<p>Here's my code</p>

<pre><code>public class ImageUtils
{
    const int sizeThumb = 69;

    public static int uploadImage(int memberid, Image thumbimage)
    {
        MemoryStream stream = new MemoryStream();
        thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
        Byte[] thumbbytes = stream.ToArray();

        //int length = Convert.ToInt32(data.Length);
        //byte[] thumbimage = new byte[length];
        //data.Read(thumbimage, 0, length);
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["FMMImages"].ConnectionString);
        SqlCommand command = new SqlCommand("update Images_temp set thumbimage = @thumbimage where memberid=@memberid", connection);
        SqlParameter param0 = new SqlParameter("@thumbimage", SqlDbType.Image);
        param0.Value = thumbbytes;
        command.Parameters.Add(param0);

        connection.Open();

        object result = command.ExecuteScalar();
        connection.Close();
        if (result != null)
        {
            return System.Convert.ToInt32(result);
        }
        else
        { 
            return 0;
        }
    }
</code></pre>

<p>aspx.cs where I'm calling the uploadimage
      image CroppedWaterMarkImage
        ......</p>

<pre><code>    ImageUtils.uploadImage(memberid, CroppedWaterMarkImage);
</code></pre>

<p>Error in the uploadimage function:</p>

<pre><code>     MemoryStream stream = new MemoryStream();
     thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
     Byte[] thumbbytes = stream.ToArray();
</code></pre>

<blockquote>
  <p>System.ArgumentException: Parameter is not valid.</p>
</blockquote>

<p>Thanks
Sun</p>
