<%@ WebHandler Language="C#" Class="Image" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Web.SessionState;
class Image : IHttpHandler, IRequiresSessionState
{public void ProcessRequest(HttpContext context)
{context.Response.ContentType = "image/gif";
Bitmap b = new Bitmap(200, 60);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, 200, 60);
Font font = new Font(FontFamily.GenericSansSerif, 48, FontStyle.Bold, GraphicsUnit.Pixel);
Random r = new Random();
string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
string letter;
StringBuilder Lt = new StringBuilder();
for (int x = 0; x < 5; x++)
{letter = letters.Substring(r.Next(0, letters.Length - 1), 1);
Lt.Append(letter);
g.DrawString(letter, font, new SolidBrush(Color.Black), x * 38, r.Next(0, 15));
}
Pen linepen = new Pen(new SolidBrush(Color.Black), 2);
for (int x = 0; x < 6; x++)
g.DrawLine(linepen, new Point(r.Next(0, 199), r.Next(0, 59)), new Point(r.Next(0, 199), r.Next(0, 59)));
b.Save(context.Response.OutputStream, ImageFormat.Gif);
context.Session["image"] =Lt;
context.Response.End();
}
public bool IsReusable
{get{return true;}
}
}
0 Comments:
Post a Comment