您好我正在尝试从数据库中获取字节数组并将其转换为可用于在我的 .aspx 页面中显示来自数据库的图像的东西。我正在使用严格的 c#。
这是我的代码。
SqlCommand picCommand = connection.CreateCommand();
picCommand.CommandText = ("SELECT ItemImage FROM Inventory WHERE ItemName = '" + DropDownList1.SelectedItem.Text + "';");
connection.Open();
object returnPic;
returnPic = picCommand.ExecuteScalar();//value that is read as the byte array or intended to be read as byte array.
connection.Close();
UTF8Encoding utf8 = new UTF8Encoding();
//where i intend to convert the
byte[] image = utf8.GetBytes(returnPic.ToString());
System.Drawing.Image myImage;
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(image, 0, image.Length);
myImage = Bitmap.FromStream(inStream);
}
this.ItemImageBox.Equals(myImage);
代码编译并运行,但是当它执行 myImage = Bitmap.FromStream(instream) 行时,我收到此错误 System.ArgumentException: Parameter is not valid。我实际上是通过查看各种不同的来源获得了这段代码,所以也许这里有人可以告诉我我是否做错了什么。
提前谢谢!