How to Convert System.Drawing.Image to Byte Array?

后端 未结 2 1513
广开言路
广开言路 2021-01-11 17:39

Hi I\'m trying to convert image to byte array to pass it into sql as byte(). Im trying to use Image Converter but it keeps failing

Dim converter As New Image         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 18:31

    The VB.NET TypeOf operator doesn't do what you think it does. Somewhat confusing perhaps due to the C# typeof operator. The VB.NET equivalent is the GetType() function. This works fine:

    Dim converter As New ImageConverter
    nRow.Signature = converter.ConvertTo(imgSignature, GetType(Byte()))
    

    The type converter uses a MemoryStream to make the conversion, using the PNG image format.

提交回复
热议问题