title: vb.net image save to memory stream results in an ArgumentNullException
body: <p>In VB.NET I have the following function that allows me to calculate a hash for an image I have not yet saved to a file :</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Function pictureHash(ByVal image As System.Drawing.Image) As String
    Try
      If image Is Nothing Then Return Nothing
      Dim ha As HashAlgorithm = HashAlgorithm.Create()
      Dim ms As New MemoryStream()
      image.Save(ms, image.RawFormat)
      ms.Position = 0
      Dim imageHash As Byte() = ha.ComputeHash(ms)
      ms.Close()
      Return BitConverter.ToString(imageHash)
    Catch ex As Exception
      Return Nothing
    End Try
  End Function
  </code></pre>
  
  <p>The problem is I get an ArgumentNullException on the instruction <code>image.Save(ms, image.rawFormat)</code>.</p>
  
  <p>Here is the detail of the exception :</p>
  
  <pre><code>System.ArgumentNullException occurred
    Message="Value cannot be null. Parameter name: encoder"
    ParamName="encoder"
    Source="System.Drawing"
    StackTrace:
         at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
         at System.Drawing.Image.Save(Stream stream, ImageFormat format)
         at MyProgram.pictureHash(Image image)
  </code></pre>
  
  <p>The thing is, when I look at the stack trace, the last call to Image.Save with 3 parameters (the one that crashes) isn't even made by me, but by the previous Image.Save call.</p>
  
  <p>Any idea what should I do ?</p>
  
  <p>Many thanks in advance for your help,</p>
  
  <p>Regards,</p>
  
  <p>Joël</p>