How can I write an extension method that converts a System.Drawing.Bitmap to a byte array?
- by Patrick Szalapski
How can I write an extension method that converts a System.Drawing.Bitmap to a byte array? Why not:
<Extension()> _
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
Yet when I use that, I get "System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+." What am I doing wrong?