验证码的生成
生成验证码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class CreateCode : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; using (Bitmap bm = new Bitmap(80, 25))//画板 bitmap { using (Graphics gp = Graphics.FromImage(bm)) //画笔 graphics { // gp.FillRectangle(Brushes.Red, 0, 0, bm.Width, bm.Height); //填充画板,颜色,从某点开始 宽度高度 // gp.FillRectangle(Brushes.White, 1, 1, bm.Width - 2, bm.Height - 2); gp.DrawString(MakeCode(), new Font("楷体", 12), Brushes.Yellow,22,5); bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//将这个画板输出 } } } public string MakeCode() { string result = ""; string ku = "0123456789abcdefghijklmnopqistuvwxyzABCDEFGHIJKLMNOPQISTUVWXYZ"; Random ra = new Random(); for (int i = 0; i < 4; i++) { result += ku[ra.Next(0, ku.Length)]; } return result; }
知识没有高低贵贱之分。