<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Web.SessionState;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
public class Handler : IHttpHandler, IRequiresSessionState
{
static PrivateFontCollection pfc = null;
public void ProcessRequest(HttpContext context)
{
string checkCode = context.Request.QueryString["ValidateCode"];
if (checkCode == null)
checkCode = "0 0 0 0";
context.Session["GetCode"] = checkCode;
int iwidth = 108;//(int)(checkCode.Length * 11.5);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 45);
Graphics g = Graphics.FromImage(image);
Random random = new Random(System.DateTime.Now.Millisecond);
//Font f = new System.Drawing.Font("Arial", 16, System.Drawing.FontStyle.Regular);
//Brush b = new System.Drawing.SolidBrush(Color.Black);
Brush b = new System.Drawing.SolidBrush(Color.FromArgb(4683611));
//g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
//Color color = Color.FromArgb(16775149);
g.Clear(Color.FromArgb(237, 247, 255));
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.NoWrap;
Matrix matrix = new Matrix();
float offsetx = -35, offsety = 0;
g.SmoothingMode = SmoothingMode.AntiAlias;
for (int i = 0; i < checkCode.Length; i++)
{
int fsize = random.Next(24,28);
Font f = CreateFont(context.Server.MapPath("tt0767m_.TTF"), fsize, FontStyle.Bold, GraphicsUnit.Point, 0);
SizeF size = g.MeasureString(checkCode[i].ToString(), f);
matrix.RotateAt(random.Next(-15, 10), new PointF(offsetx+size.Width/2, offsety+size.Height/2));
g.Transform = matrix;
g.DrawString(
checkCode[i].ToString(),
f,
Brushes.Green,
new RectangleF(
offsetx,
offsety,
image.Width,
image.Height),
format);
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Web.SessionState;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
public class Handler : IHttpHandler, IRequiresSessionState
{
static PrivateFontCollection pfc = null;
public void ProcessRequest(HttpContext context)
{
string checkCode = context.Request.QueryString["ValidateCode"];
if (checkCode == null)
checkCode = "0 0 0 0";
context.Session["GetCode"] = checkCode;
int iwidth = 108;//(int)(checkCode.Length * 11.5);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 45);
Graphics g = Graphics.FromImage(image);
Random random = new Random(System.DateTime.Now.Millisecond);
//Font f = new System.Drawing.Font("Arial", 16, System.Drawing.FontStyle.Regular);
//Brush b = new System.Drawing.SolidBrush(Color.Black);
Brush b = new System.Drawing.SolidBrush(Color.FromArgb(4683611));
//g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
//Color color = Color.FromArgb(16775149);
g.Clear(Color.FromArgb(237, 247, 255));
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.NoWrap;
Matrix matrix = new Matrix();
float offsetx = -35, offsety = 0;
g.SmoothingMode = SmoothingMode.AntiAlias;
for (int i = 0; i < checkCode.Length; i++)
{
int fsize = random.Next(24,28);
Font f = CreateFont(context.Server.MapPath("tt0767m_.TTF"), fsize, FontStyle.Bold, GraphicsUnit.Point, 0);
SizeF size = g.MeasureString(checkCode[i].ToString(), f);
matrix.RotateAt(random.Next(-15, 10), new PointF(offsetx+size.Width/2, offsety+size.Height/2));
g.Transform = matrix;
g.DrawString(
checkCode[i].ToString(),
f,
Brushes.Green,
new RectangleF(
offsetx,
offsety,
image.Width,
image.Height),
format);