asp.net总结
生成验证码
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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。