如何将System.Drawing.Image转换为字节数组?
问题描述:
您好我正在尝试将图像转换为字节数组以将其作为byte()传递给sql。我试图使用Image Converter但它一直失败
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 ImageConverter
nRow.Signature = converter.ConvertTo(imgSignature, TypeOf(Byte())
我一直得到的错误是字节是一种类型而不是表达式
the error I keep getting is byte is a type not expression
答
VB.NET TypeOf运算符没有按照你的想法做到。有些混乱可能是由于C# typeof
运算符.VB.NET等价物是GetType()函数。这很好用:
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())
类型转换器使用MemoryStream以PNG图像格式进行转换。
The type converter uses a MemoryStream to make the conversion, using the PNG image format.