欢迎光临
我们一直在努力

ASP.NET中制作图形-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

这个程序经过修改 现在作计数器的话 只能做黑白的 计数器,谁有办法 能够做出 复杂的 图形计数器?

<% @page language="c#" %>

<% @import namespace="system.drawing" %>

<% @import namespace="system.io" %>

<% @import namespace="system.drawing.imaging" %>

<%

response.expires = 0;

bitmap newbitmap = null;

graphics g = null ;

string str2render = request.querystring.get("hitcount");

if (null == str2render) str2render = "12345";

string strfont = request.querystring.get("hitfontname");

if (null == strfont) strfont = "楷体_gb2312";

int nfontsize = 12;

try

{

nfontsize = request.querystring.get("hitfontsize").toint32();

}

catch

{

// do nothing, just ignore

}

string strbackgroundcolorname = request.querystring.get("hitbackgroundcolor");

color clrbackground = color.white;

try

{

if (null != strbackgroundcolorname)

clrbackground = colortranslator.fromhtml(strbackgroundcolorname);

}

catch

{

}

string strfontcolorname = request.querystring.get("hitfontcolor");

color clrfont = color.black;

try

{

// format in the url: %23xxxxxx

if (null != strfontcolorname)

clrfont = colortranslator.fromhtml(strfontcolorname);

}

catch

{

}

try

{

font fontcounter = new font(strfont, nfontsize);

newbitmap = new bitmap(1,1,pixelformat.format32bppargb);

g = graphics.fromimage(newbitmap);

sizef stringsize = g.measurestring(str2render, fontcounter);

int nwidth = (int)stringsize.width;

int nheight = (int)stringsize.height;

g.dispose();

newbitmap.dispose();

newbitmap = new bitmap(nwidth,nheight,pixelformat.format32bppargb);

g = graphics.fromimage(newbitmap);

g.fillrectangle(new solidbrush(clrbackground), new rectangle(0,0,nwidth,nheight));

g.drawstring(str2render, fontcounter, new solidbrush(clrfont), 0, 0);

memorystream tempstream = new memorystream();

newbitmap.save(tempstream,imageformat.gif);

response.clearcontent();

response.contenttype = "image/gif";

response.binarywrite(tempstream.toarray());

response.end();

}

catch (exception e)

{

response.write(e.tostring());

}

finally

{

if (null != g) g.dispose();

if (null != newbitmap) newbitmap.dispose();

}

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET中制作图形-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章