c# - "Parameter is not valid"System.Drawing.Image.FromStream() 方法异常

标签 c# asp.net system.drawing

我在我的网站上使用 Image.FromStream 方法遇到了困难。下面的代码在我的电脑上运行完美。但是当我把它上传到测试服务器时,它总是给我“参数无效”的异常。

if (!afuImageFile.IsUploading && afuImageFile.HasFile)
{
    System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);
}

afuImageFile 是 Ajax 工具包中的一个 AsynFileUploader 控件。 afuImageFile.FileContent 是一个 HttpInputStream。我想我需要对某个文件夹添加一些权限。谁能帮帮我?

最佳答案

请确保您的 FileContent 流作为其位置设置为 0。

否则,您可能希望通过更改调用来停用图像验证:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);

到:

System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent, true, false);

参见 Image.FromStream检查其他重载。

关于c# - "Parameter is not valid"System.Drawing.Image.FromStream() 方法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3586878/

相关文章:

c# - 验证 double /小数是否为货币 C#

c# - 连接未关闭。连接的当前状态是打开的。 C#错误

c# - ASP.Net MVC 删除带有 FK 约束的记录

asp.net - ASP .net 应用程序中的遗留 html 表单

c# - 源文件正确,使用system.drawing打印将实际打印移至右侧和底部

asp.net - 没有 System.Drawing/GDI+ 的 asp.net/c# 中的图像处理

c# - 服务器中的 SFTP 上传失败

c# - 如何使用来自 sql 的表数据填充 gridview

asp.net - WebAPI 生命周期/请求队列

c# - (C#) 如何使用高度 = 6 的 Tahoma 绘制 "a"