加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 18:32:28 所属栏目:百科 来源:网络整理
导读:我有一个函数,它首先从磁盘读取图像,调整大小,然后保存到另一个目录. 当我使用Bitmap.Save(目录theimagename)时,它返回错误,如我在问题标题中所述. 我检查了目录是否正确,并且该目录中不存在给定的图像名称. 奇怪的是,相同的代码在本地机器上运行良好.但是当
我有一个函数,它首先从磁盘读取图像,调整大小,然后保存到另一个目录.

当我使用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:InetpubvhostsDomainNamehttpdocsProductImages500pxgigabyte_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:inetpubvhostsbatuhanakcay.comhttpdocsApp_CodeUtilities.cs:181
   Link.ToProductImage(String fileName) in c:inetpubvhostsbatuhanakcay.comhttpdocsApp_CodeLink.cs:79
   Product.PopulateControls(ProductDetails pd) in c:inetpubvhostsbatuhanakcay.comhttpdocsProduct.aspx.cs:37
   Product.Page_Load(Object sender,EventArgs e) in c:inetpubvhostsbatuhanakcay.comhttpdocsProduct.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.

你检查了权限吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读