c# - 错误:“参数无效”,将字节 [] 转换为图像时
问题描述
因此,我试图将字节数组转换为图像,但出现此错误:
System.ArgumentException:“参数无效。” byte[] 来自 SQL Server 中的数据库,其中数据类型为“图像”。
我已经尝试了在 StackOverflow 的其他问题中找到的所有解决方案,但它们对我不起作用;这是我的代码:
//biblioteca.herramientas is where I make the connection with the server
DataSet dataset_Image;
dataset_Image = Biblioteca.Herramientas(string.Format("SELECT * FROM Image WHERE id_Image = " + 1));
array = (byte[])dataset_Image.Tables[0].Rows[0]["image"];
public byte[] TheImage
{
set
{
theImage = ImageConversor.ByteArrayToImage(value);
PictureBox2.Image = theImage;
}
}
这是我有错误的地方:
public class ImageConversor
{
public static Image ByteArrayToImage(byte[] byteArrayIn)
{ //HERE THE ERROR APPEARS
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
The following picture is the SQL table that I am accessing to:
仅此而已,如果您需要更多信息,我会分享,谢谢您的宝贵时间,希望您有美好的一天。(:
编辑: 如果我直接从 SQLS 添加图片,代码工作正常,将列“图像”(存储图片的位置)数据类型从“图像”更改为“varbinary(MAX)”,然后使用以下代码插入图像:
insert into Image select * from openrowset (bulk N'picture directory', single_blob) as image
问题是我不能用它来添加图片,但我不知道,也许它有助于解决这个问题:/
解决方案
推荐阅读
- google-chrome - SpringBoot 2 http基本安全在chrome上总是401,但在邮递员上总是200
- apache-kafka - 如何在 Micronaut 中实现 HTTP 端点以暂停消费来自 Kafka 的消息?
- sql - MS Access 查询:将多行中的多列合并到单个字段中
- mysql - 错误代码:1054。“where 子句”中的未知列“sdate”
- angular - (Angular) 完整的应用程序同时运行两次
- c++ - 从结构化数组中读取信息
- python - 遍历 pandas DataFrame 中的列表
- gcloud - 将 gcloud 服务帐号限制为特定存储桶
- sql-server - Exec 语句中“=”附近的语法不正确
- javascript - 如何使用 Jest 和 React 测试函数