/*
豆腐制作 都是精品
http://www.asp888.net 豆腐技术站
如转载 请保留版权信息
*/
这个程序经过修改 现在作计数器的话 只能做黑白的 计数器,谁有办法 能够做出 复杂的 图形计数器?
1 @Page Language="C#"
1 @Import Namespace="System.Drawing"
1 @Import Namespace="System.IO"
1 @Import Namespace="System.Drawing.Imaging"
1
2Response.Expires = 0;
3Bitmap newBitmap = null;
4Graphics g = null ;
5string str2Render = Request.QueryString.Get("HitCount");
6if (null == str2Render) str2Render = "12345";
7string strFont = Request.QueryString.Get("HitFontName");
8if (null == strFont) strFont = "楷体_GB2312";
9int nFontSize = 12;
10try
11{
12nFontSize = Request.QueryString.Get("HitFontSize").ToInt32();
13}
14catch
15{
16// do nothing, just ignore
17}
18
19string strBackgroundColorname = Request.QueryString.Get("HitBackgroundColor");
20Color clrBackground = Color.White;
21try
22{
23if (null != strBackgroundColorname)
24clrBackground = ColorTranslator.FromHTML(strBackgroundColorname);
25}
26catch
27{
28}
29
30string strFontColorName = Request.QueryString.Get("HitFontColor");
31Color clrFont = Color.Black;
32try
33{
34// Format in the URL: %23xxXXxx
35if (null != strFontColorName)
36clrFont = ColorTranslator.FromHTML(strFontColorName);
37}
38catch
39{
40}
41
42try
43{
44Font fontCounter = new Font(strFont, nFontSize);
45newBitmap = new Bitmap(1,1,PixelFormat.Format32bppARGB);
46g = Graphics.FromImage(newBitmap);
47SizeF stringSize = g.MeasureString(str2Render, fontCounter);
48int nWidth = (int)stringSize.Width;
49int nHeight = (int)stringSize.Height;
50g.Dispose();
51newBitmap.Dispose();
52newBitmap = new Bitmap(nWidth,nHeight,PixelFormat.Format32bppARGB);
53g = Graphics.FromImage(newBitmap);
54g.FillRectangle(new SolidBrush(clrBackground), new Rectangle(0,0,nWidth,nHeight));
55g.DrawString(str2Render, fontCounter, new SolidBrush(clrFont), 0, 0);
56MemoryStream tempStream = new MemoryStream();
57newBitmap.Save(tempStream,ImageFormat.GIF);
58Response.ClearContent();
59Response.ContentType = "image/GIF";
60Response.BinaryWrite(tempStream.ToArray());
61Response.End();
62}
63catch (Exception e)
64{
65Response.Write(e.ToString());
66}
67finally
68{
69if (null != g) g.Dispose();
70if (null != newBitmap) newBitmap.Dispose();
71}
作者:豆腐