2016-12-06 95 views
0

以下是我的代码使用保存图像保存图像,一般性错误的GDI +,同时使用Image.Save(文件名,ImageFormat.Jpeg)

HttpPostedFile postedFile = request.Files[file]; 

string directoryPath = @"~\PostImage\"; 

Image image = Image.FromStream(postedFile.InputStream); 

string Filepath = Server.MapPath(directoryPath); 

string Filename = Filepath + "PostImageFile.jpg"; 

result.FieldName = Filename; 

image.Save(Filename, ImageFormat.Jpeg); 

我得到错误的image.Save(Filename, ImageFormat.Jpeg);

回答

0

最后我得到了解决方案,
首先我在我的本地机器上创建文件夹“PostedImages”在应用程序目录中。
然后在性质文件夹的 “安全” 选项卡增加了三个新的用户
1)IIS_USRS
2)IUSR
3)NETWORK SERVICE
对于给定的FullControl访问权限的每个用户所有这些用户。
然后在应用程序中添加该文件夹并发布到Azure。
现在,一切工作正常。
代码变了样:

string Filepath = Server.MapPath(@"~\PostedImages\"); 
string FilenameServer = Filepath + "PostedImage.jpg"; 
Image img = Image.FromStream(postedFile.InputStream); 
Bitmap bmp = img as Bitmap; 
Graphics g = Graphics.FromImage(bmp); 
Bitmap bmpNew = new Bitmap(bmp); 
g.DrawImage(bmpNew, new System.Drawing.Point(0,0)); 
g.Dispose(); 
bmp.Dispose(); 
img.Dispose(); 
bmpNew.Save(FilenameServer, ImageFormat.Jpeg); 

我从http://www.aspforums.net/Threads/159114/Error-when-hosted-in-IIS-Server-SystemRuntimeInteropServicesExternalException-0x80004005-A-generic-error-occurred-in-GDI/

得到解决
相关问题