1: <%@ WebHandler Language="C#" Class="Handler" %>
2:
3: using System;
4: using System.Web;
5: using System.Drawing;
6: using System.Drawing.Drawing2D;
7: using System.Drawing.Imaging;
8: using System.IO;
9:
10:
11: public class Handler : IHttpHandler
12: {
13:
14: public bool IsReusable { get { return false; } }
15:
16: public void ProcessRequest (HttpContext context)
17: {
18: Bitmap bmp;
19: Graphics g;
20:
21: try
22: {
23: int w = Convert.ToInt32(context.Request.QueryString["width"]);
24: int h = Convert.ToInt32(context.Request.QueryString["height"]);
25: string t = context.Request.QueryString["text"];
26: string f = context.Request.QueryString["font"];
27: int s = Convert.ToInt32(context.Request.QueryString["size"]);
28: Color c = Color.FromName(context.Request.QueryString["color"]);
29:
30: bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
31: g = Graphics.FromImage(bmp);
32:
33: g.Clear(Color.Transparent);
34: g.DrawString(
35: t.Replace("_", "")
36: ,new Font(f, s, FontStyle.Bold)
37: ,new SolidBrush(c), 0, 0);
38: }
39: catch
40: {
41: bmp = new Bitmap(40, 18, PixelFormat.Format32bppArgb);
42: g = Graphics.FromImage(bmp);
43: g.Clear(Color.Yellow);
44:
45: g.DrawString(
46: "error"
47: ,new Font("Tahoma", 10, FontStyle.Bold)
48: ,new SolidBrush(Color.Red), 0, 0);
49: }
50:
51: MemoryStream oStream = new MemoryStream();
52: bmp.Save(oStream, ImageFormat.Png);
53:
54: context.Response.ClearContent();
55: context.Response.ContentType = "image/png";
56: context.Response.BinaryWrite(oStream.ToArray());
57: context.Response.End();
58:
59: bmp.Dispose();
60: g.Dispose();
61: }
62: }