在Bitmap.Save&QUOT ASP.NET错误;异常(0X80004005):在GDI +&QUOT发生一般性错误。 [英] ASP.NET error on Bitmap.Save "Exception (0x80004005): A generic error occurred in GDI+."

查看:123
本文介绍了在Bitmap.Save&QUOT ASP.NET错误;异常(0X80004005):在GDI +&QUOT发生一般性错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,它首先从磁盘中读取图像,调整其大小,然后保存到另一个目录。

当我使用Bitmap.Save(目录+ theimagename)正如我在问题的标题说,它会返回错误。

我检查的目录是正确的,给定的图像名称并不在该目录存在。

是什么奇怪的是,同样的code在本地机器上的伟大工程。但是当我把它上传到我的共享虚拟主机空间,它只是不工作。

在code如下。

  bmpOut =新位图(尺寸,大小);
图形G = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White,0,0,尺寸,大小);
INT topBottomPadding = 0; INT leftRightPadding = 0;
如果(尺寸和GT; lnNewWidth + 1)
    leftRightPadding = Convert.ToInt32((大小 - lnNewWidth)/ 2);
否则,如果(大小和GT; lnNewHeight + 1)
    topBottomPadding = Convert.ToInt32((大小 - lnNewHeight)/ 2);
g.DrawImage(loBMP,leftRightPadding,topBottomPadding,lnNewWidth,lnNewHeight);
BMP位图=新位图(bmpOut);
如果(BMP!= NULL)
    bmp.Save(ResizedOutput); // C:\\的Inetpub \\虚拟主机\\域名\\的httpdocs \\ ProductImages \\ 500像素\\ gigabyte_ga_ep45_ds4_profilelarge [1] .JPG
bmp.Dispose();
bmpOut.Dispose();
g.Dispose();
loBMP.Dispose();

堆栈跟踪:

  [ExternalException(0X80004005):GDI +中发生一般性错误]
   System.Drawing.Image.Save(字符串的文件名,图像codecInfo EN codeR,恩coderParameters EN coderParams)377630
   System.Drawing.Image.Save(字符串的文件名,格式的imageformat)+69
   System.Drawing.Image.Save(字符串文件名)+25
   Utilities.ResizeImage(字符串文件名,字符串模式)在C:\\的Inetpub \\虚拟主机\\ batuhanakcay.com \\的httpdocs \\ APP_ code \\ Utilities.cs:181
   Link.ToProductImage(字符串文件名),在C:\\的Inetpub \\虚拟主机\\ batuhanakcay.com \\的httpdocs \\ APP_ code \\ Link.cs:79
   Product.PopulateControls(产品详细PD)在C:\\的Inetpub \\虚拟主机\\ batuhanakcay.com \\的httpdocs \\ Product.aspx.cs:37
   Product.Page_Load(对象发件人,EventArgs e)在C:\\的Inetpub \\虚拟主机\\ batuhanakcay.com \\的httpdocs \\ Product.aspx.cs:20


解决方案

从的 ASP网 - GDI +,并保存JPG或BMP服务器上


  

使用GDI时的时间,99.9%,一般错误发生'指
  目录中,您要保存到
  不ahve适当的权限。
  通常情况下,你需要确保
  目录允许asp.net到
  修改文件。


你检查的权限?

I have a function which first reads an image from disk, resizes it and then saves to another directory.

when i use the Bitmap.Save(directory + theimagename) it returns the error as i stated in the question title.

i checked the directory is right, and the given image name doesn't exist in that dir.

what is weird, is that the same code works great on the local machine. but when i upload it to my shared hosting space, it just doesn't work.

the code is below.

bmpOut = new Bitmap(Size, Size);
Graphics g = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White, 0, 0, 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();

stack trace:

[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

解决方案

From 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.

Did you check the permissions?

这篇关于在Bitmap.Save&QUOT ASP.NET错误;异常(0X80004005):在GDI +&QUOT发生一般性错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆