可能重复:
“Parameter not valid” exception loading System.Drawing.Image
我在DB中插入图像。
这是我的代码
public class ImageUtils
{
const int sizeThumb = 69;
public static int uploadImage(int memberid, Image thumbimage)
{
MemoryStream stream = new MemoryStream();
thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] thumbbytes = stream.ToArray();
//int length = Convert.ToInt32(data.Length);
//byte[] thumbimage = new byte[length];
//data.Read(thumbimage, 0, length);
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["FMMImages"].ConnectionString);
SqlCommand command = new SqlCommand("update Images_temp set thumbimage = @thumbimage where memberid=@memberid", connection);
SqlParameter param0 = new SqlParameter("@thumbimage", SqlDbType.Image);
param0.Value = thumbbytes;
command.Parameters.Add(param0);
connection.Open();
object result = command.ExecuteScalar();
connection.Close();
if (result != null)
{
return System.Convert.ToInt32(result);
}
else
{
return 0;
}
}
aspx.cs我正在调用uploadimage image CroppedWaterMarkImage ......
ImageUtils.uploadImage(memberid, CroppedWaterMarkImage);
uploadimage函数出错:
MemoryStream stream = new MemoryStream();
thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] thumbbytes = stream.ToArray();
System.ArgumentException:参数无效。
由于 太阳
答案 0 :(得分:1)
由于内存泄漏,这些人遇到了与Images和MemoryStream()类似的问题:
通过调用System.Drawing.Bitmap而不是System.Drawing.Image来解决此链接:
(内存泄漏/损坏和/或API的选择)可能适用于您的方案。
还要确保图像文件有效。