0

当我将此代码中的数据库字节数组转换为图像时,出现一个错误“参数无效”。

try
{
    DataTable dt = dbo.GetRecordsWithQuery("select * from Users where UserID='" +Session["userid"].ToString()+ "'");
    byte[] image_user = (byte[])dt.Rows[0]["Image"]; // from this i got the error. Also the image_user dimension is 13
    System.Drawing.Image myimage = BinaryToImage(image_user);
    myimage.Save(Server.MapPath("~/User/images/profileImg/img1.jpg"));
    img1.ImageUrl = "~/User/images/profileImg/img1.jpg";
    url = img1.ImageUrl;
}

...

public static System.Drawing.Image BinaryToImage(byte[] binaryData)
{
    MemoryStream ms = new MemoryStream(binaryData);
    System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
    return returnImage;
}
4

0 回答 0