我在我的网站上使用 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/