码迷,mamicode.com
首页 > Web开发 > 详细

asp.net总结

时间:2015-02-19 17:28:23      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

生成验证码

技术分享
   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;
        }
画板Bitmap 画笔Graphic 控制颜色 Brushs 画字,颜色,开始xy,宽高

 

asp.net总结

标签:

原文地址:http://www.cnblogs.com/leee/p/4296174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!