title: How can I write an extension method that converts a System.Drawing.Bitmap to a byte array?
body: <p>How can I write an extension method that converts a System.Drawing.Bitmap to a byte array?  Why not:</p>
  
  <pre><code>&lt;Extension()&gt; _
  Public Function ToByteArray(ByVal image As System.Drawing.Bitmap) As Byte()
      Using ms = New MemoryStream()
          image.Save(ms, image.RawFormat)
          Return ms.ToArray()
      End Using
  End Function
  </code></pre>
  
  <p>Yet when I use that, I get "System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+" thrown from the Save() operation.  What am I doing wrong?</p>