[英]C# Convert to Byte Array
如何将VBNet代码转换为C#? ( ByteToImage
是用户定义的函数,用于将字节数组转换为位图。
Dim Bytes() As Byte = CType(SQLreader("ImageList"), Byte())
picStudent.Image = jwImage.ByteToImage(Bytes)
我试过了
byte[] Bytes = Convert.ToByte(SQLreader("ImageList")); // Error Here
picStudent.Image = jwImage.ByteToImage(Bytes);
但它会产生一条错误消息: Cannot implicitly convert type 'byte' to 'byte[]'
我所做的基本上是将图像从数据库转换为字节数组,并将其显示在图片框上。
byte[] Bytes = (byte[]) SQLreader("ImageList");
picStudent.Image = jwImage.ByteToImage(Bytes);
尝试这个
byte[] Bytes = (byte[])SQLreader("ImageList");
希望这可以帮助
问题是您有一个字节数组(C#中的byte[]
和VB.Net中的Byte()
),但是Convert.ToByte
调用仅返回一个简单的byte
。 为此,您需要将SQLreader
的返回值SQLreader
为byte[]
。
在C#中没有完美的CType
类似构造,但是在这里进行简单的转换应该可以解决问题
byte[] Bytes = (byte[])SQLreader("ImageList");
CType等同于类型转换,不是实际转换。此外,Convert.ToByte尝试将其输入转换为单个字节,而不是数组。 等效代码是
byte[] bytes=(byte[])SQLreader("ImageList");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.