目前我正在使用 ASP.NET 和 C# 将图像存储到 MySQL(使用 blob 数据类型)。我已成功将其存储到数据库中,但现在的问题是,如何将其检索byte[]
为图像格式?
功能:code to convert byte[] to image
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms); --> here gives me error as `parameter is not valid`
return returnImage;
}
检索为数据表...
if (dt1.Rows.Count > 0)
{
byteArrayToImage((byte[]) dt1.Rows[0]["PortfolioSlideImages"]);
//MemoryStream ms = new MemoryStream((byte[])dt1.Rows[0]["PortfolioSlideImages"]);
//Image returnImage = Image.FromStream(ms);
//return returnImage;
}