c# - GDI+ error when ASHX deployed to Azure -
i have following code composing ashx file hosted on 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); } }
when run locally code operates , generates correct result. when deployed azure following:
a generic error occurred in gdi+.
description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.
exception details: system.runtime.interopservices.externalexception: generic error occurred in gdi+.
anyone have ideas? in advance
so, found answer question, or @ least 1 of answers question.
thanks rick strahls blog entry. while bitmap cloning technique step in right direction (why microsoft?) apparently when attempt output png ashx have take special consideration.
this consideration saving bitmap memorystream before save real location.
Comments
Post a Comment