向输出流输出图像时,是否需要临时存储?当将图像保存到文件时,我会收到通常与文件夹权限错误相关的“通用GDI+”错误。
我对这个图像唯一的操作是添加一些文本。即使在不进行修改的情况下直接输出图像,我仍然会收到错误。例如,执行以下操作将导致出现错误:
using (Bitmap image = new Bitmap(context.Server.MapPath("images/stars_5.png")))
{
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
}
在我的本地机器上运行Windows 7,IIS 7.5和ASP.NET 2.0都很正常,但问题出现在运行Windows Server 2003,IIS 6和ASP.NET 2.0的QA服务器上。
导致错误的代码行是:
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
这是堆栈跟踪:
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +378002
System.Drawing.Image.Save(Stream stream, ImageFormat format) +36
GetRating.ProcessRequest(HttpContext context) in d:\inetpub\wwwroot\SymInfoQA\Apps\tools\Rating\GetRating.ashx:54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75