0
我有下面的代码编写托管在Azure中ASHX文件:GDI +错误时ASHX部署到Azure的
public void ProcessRequest(HttpContext context)
{
int number;
try
{
number = int.Parse(context.Request.QueryString["number"]);
}
catch
{
number = -1;
}
var bitmap = new Bitmap(173, 173);
DrawImage(bitmap, number);
context.Response.ContentType = "image/png";
bitmap.Save(context.Response.OutputStream, ImageFormat.Png);
context.Response.Flush();
}
private void DrawImage(Bitmap bitmap, int number)
{
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.FillRectangle(GetBrush(number), 0, 0, 173, 173);
Font font = new Font("Segoe UI", 40f, FontStyle.Bold);
StringFormat textFormat = new StringFormat
{
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
Rectangle rectangle = new Rectangle(0, 0, 160, 173);
graphics.DrawString("76", font, Brushes.Black, rectangle, textFormat);
font = new Font("Arial", 16, FontStyle.Bold);
textFormat = new StringFormat
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Near
};
rectangle = new Rectangle(10, 10, 163, 163);
graphics.DrawString("YOUR NUMBER", font, Brushes.Black, rectangle, textFormat);
}
}
在本地运行这段代码完全进行处理并产生正确的结果。部署到Azure时,出现以下错误:
GDI +中发生了一般性错误。
描述:在执行 当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.Runtime.InteropServices.ExternalException:GDI +中发生 一般错误。
任何人有任何想法?在此先感谢