zoukankan      html  css  js  c++  java
  • 一般处理程序生成验证码图片

        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "image/jpeg";
            //获得验证码符号
            string code = GetCode();
            Image img = GetImage(code);
            //保存生成的验证码图片
            img.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        }
    
        /// <summary>
        /// 生成验证码图片
        /// <summary>
        private Image GetImage(string code) {
            Bitmap bitmap = new Bitmap(85, 40);
            //画板
            Graphics g = Graphics.FromImage(bitmap);
            //在画板上输出符号
            g.DrawString(code, new Font("楷体", 24), Brushes.Green, 5, 5);
            return bitmap;
        }
    
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        private string GetCode() {
            string str = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
            string code = "";
            Random r = new Random();
            for (int i = 0; i < 4; i++) {
                //存储验证码符号
                code += str[r.Next(0, str.Length)];
            }
            return code;
        }
    

      

    下面是我用一般处理程序生成的10张验证码图片(给大家看看效果)

                    

                    

  • 相关阅读:
    ShaderLab 枚举常量
    PHP to .NET Compiler
    填充圆算法
    战争迷雾
    A*
    寻路算法
    Unity中将动画片段保存为文件
    令人蛋疼的错误提示 0xcdcdcdcd ,0xdddddddd ,0xfeeefeee ,0xcccccccc ,0xabababab
    2D光照
    Rider 2018 激活码
  • 原文地址:https://www.cnblogs.com/rampb/p/3393184.html
Copyright © 2011-2022 走看看