c# – Bitmap.Save上的ASP.NET错误“异常(0x80004005):GDI中发生了一般错误.”

我有一个函数,它首先从磁盘读取图像,调整大小,然后保存到另一个目录.

当我使用Bitmap.Save(目录theimagename)时,它返回错误,如我在问题标题中所述.

我检查了目录是否正确,并且该目录中不存在给定的图像名称.

奇怪的是,相同的代码在本地机器上运行良好.但是当我将它上传到我的共享主机空间时,它只是不起作用.

代码如下.

bmpOut = new Bitmap(Size,Size);
Graphics g = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.drawing2d.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White,Size,Size);
int topBottomPadding = 0; int leftRightPadding = 0;
if (Size > lnNewWidth + 1)
    leftRightPadding = Convert.ToInt32((Size - lnNewWidth) / 2);
else if (Size > lnNewHeight + 1)
    topBottomPadding = Convert.ToInt32((Size - lnNewHeight) / 2);
g.DrawImage(loBMP,leftRightPadding,topBottomPadding,lnNewWidth,lnNewHeight);
Bitmap bmp = new Bitmap(bmpOut);
if (bmp != null)
    bmp.Save(ResizedOutput); // C:\Inetpub\vhosts\DomainName\httpdocs\Productimages\500px\gigabyte_ga_ep45_ds4_profilelarge[1].jpg
bmp.dispose();
bmpOut.dispose();
g.dispose();
loBMP.dispose();

堆栈跟踪:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
   System.Drawing.Image.Save(String filename,ImageCodecInfo encoder,EncoderParameters encoderParams) +377630
   System.Drawing.Image.Save(String filename,ImageFormat format) +69
   System.Drawing.Image.Save(String filename) +25
   Utilities.ResizeImage(String fileName,String mode) in c:\inetpub\vhosts\batuhanakcay.com\httpdocs\App_Code\Utilities.cs:181
   Link.ToProductimage(String fileName) in c:\inetpub\vhosts\batuhanakcay.com\httpdocs\App_Code\Link.cs:79
   Product.PopulateControls(ProductDetails pd) in c:\inetpub\vhosts\batuhanakcay.com\httpdocs\Product.aspx.cs:37
   Product.Page_Load(Object sender,EventArgs e) in c:\inetpub\vhosts\batuhanakcay.com\httpdocs\Product.aspx.cs:20

解决方法

ASP Net – GDI+ and SAVE JPG or BMP on the server

99.9% of the time,when using GDI,‘a generic error occured’ means that the
directory you are trying to save to
doesn’t ahve the proper permissions.
Typically,you need to make sure that
directory is allowing asp.net to
modify files.

你检查了权限吗?

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...