Bitmap.Save 上的 ASP.NET 错误“异常 (0x80004005):GDI+ 中发生一般错误"

ASP.NET error on Bitmap.Save quot;Exception (0x80004005): A generic error occurred in GDI+.quot;(Bitmap.Save 上的 ASP.NET 错误“异常 (0x80004005):GDI+ 中发生一般错误.)
本文介绍了Bitmap.Save 上的 ASP.NET 错误“异常 (0x80004005):GDI+ 中发生一般错误".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

当我使用 Bitmap.Save(directory + theimagename) 时,它会返回我在问题标题中所述的错误.

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.

代码如下.

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

推荐答案

来自 ASP Net - GDI+ 并在服务器上保存 JPG 或 BMP

99.9% 的情况下,在使用 GDI 时,发生一般错误"意味着您要保存到的目录没有适当的权限.通常,您需要确保目录允许 ASP.NET修改文件.

99.9% of the time, when using GDI, 'a generic error occured' means that the directory you are trying to save to doesn't have the proper permissions. Typically, you need to make sure that the directory is allowing ASP.NET to modify files.

你检查权限了吗?

这篇关于Bitmap.Save 上的 ASP.NET 错误“异常 (0x80004005):GDI+ 中发生一般错误".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)