【问题标题】:A generic error occurred in GDI+ while saving Image using Image.Save(Filename, ImageFormat.Jpeg)使用 Image.Save(Filename, ImageFormat.Jpeg) 保存图像时 GDI+ 中发生一般错误
【发布时间】:2016-12-06 12:20:34
【问题描述】:

以下是我保存图像的代码,

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); 出现错误

【问题讨论】:

    标签: asp.net-mvc-4 c#-4.0


    【解决方案1】:

    终于找到解决办法了,
    首先,我在应用程序目录中的本地计算机 "PostedImages" 上创建了文件夹。
    然后在“安全”选项卡中文件夹的属性中添加了三个新用户
    1) IIS_USRS
    2) IUSR
    3) 网络服务
    对于所有这些用户,每个用户都被赋予了 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/得到了解决方案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 2010-12-12
      相关资源
      最近更新 更多