How can I write an extension method that converts a System.Drawing.Bitmap to a byte array?
Posted
by
Patrick Szalapski
on Stack Overflow
See other posts from Stack Overflow
or by Patrick Szalapski
Published on 2011-01-12T16:47:51Z
Indexed on
2011/01/12
16:53 UTC
Read the original article
Hit count: 182
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?
© Stack Overflow or respective owner