且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Bitmap.Save&QUOT ASP.NET错误;异常(0X80004005):在GDI +&QUOT发生一般性错误。

更新时间:2022-12-09 19:48:54

从的 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?