“Parameter is not valid” exception from System.Drawing.Image.FromStream() method

偶尔善良 提交于 2020-01-24 03:51:43

问题


I got a hard time with the Image.FromStream method in my website. The code below works perfect on my computer. But when I uploaded it to the test server, it always gives me "Parameter not valid" exception.

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

the afuImageFile is an AsynFileUploader control in Ajax Tool Kits. afuImageFile.FileContent is a HttpInputStream. I guess I need to add some permission to some folder. Can anyone help me?


回答1:


Please ensure that your FileContent stream as its position set to 0.

Otherwise, you might want to deactivate image validation by changing the call from:

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

to:

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

See Image.FromStream to check on the other overloads.



来源:https://stackoverflow.com/questions/3586878/parameter-is-not-valid-exception-from-system-drawing-image-fromstream-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!