string _fontname = request["fontname"].tostring();
int _fontsize = convert.toint16(request["fontsize"]);
string _showname = request["str"].tostring();
bitmap objbitmap = null;
graphics g = null ;
font stringfont = new font(_fontname, _fontsize, fontstyle.bold );
stringformat stringformat = new stringformat();
stringformat.formatflags = stringformatflags.nowrap;
try
{
objbitmap = new bitmap(1,1);
g = graphics.fromimage(objbitmap);
sizef stringsize = g.measurestring(_showname, stringfont);
int nwidth = (int)stringsize.width;
int nheight = (int)stringsize.height;
g.dispose();
objbitmap.dispose();
objbitmap = new bitmap(nwidth,nheight);
g = graphics.fromimage(objbitmap);
g.fillrectangle(new solidbrush(color.yellow), new rectangle(0,0,nwidth,nheight));
g.textrenderinghint = textrenderinghint.antialias;
g.drawstring(_showname, stringfont, new solidbrush(color.black), new pointf(0, 0), stringformat);
objbitmap.save(response.outputstream, imageformat.gif);
}
catch (exception ee)
{
response.write(ee.tostring());
}
finally
{
if (null != g) g.dispose();
if (null != objbitmap) objbitmap.dispose();
response.end();
}
菜鸟学堂: