如何将System.Drawing.Image转换为字节数组? [英] How to Convert System.Drawing.Image to Byte Array?

查看:321
本文介绍了如何将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.

这篇关于如何将System.Drawing.Image转换为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆