• 看不懂:asp.net网站登陆图片验证代码


    protected string GetCode()
            {//随机生成数(4个)
                string strCode = "";
                Random rand = new Random();

                string[] strs = new string[36] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
                string nNum = "";
                for (int nI = 0; nI < 4; nI++)
                {
                    nNum = strs[rand.Next(0, 35)];
                    strCode += nNum.ToString();
                }
                return strCode;
            }

            protected void DrawCode(string strCode)
            {//绘画图片
                Session["Code"] = strCode; //页面传值
                Bitmap bmp = new Bitmap(70, 22);//画布大小
                Graphics g = Graphics.FromImage(bmp);//构造图片
                g.Clear(Color.Green);//背景色
                /*
                 //线条
                Pen blackPen = new Pen(Color.Red, 1);
                Rectangle rect = new Rectangle(10, 0, 100, 20);
                float startAngle = 45.0F;
                float sweepAngle = 270.0F;
               g.DrawArc(blackPen, rect, startAngle, sweepAngle);
                */
                Random random = new Random();
                for (int i = 0; i < 135; i++)
                {
                    int x = random.Next(bmp.Width);
                    int y = random.Next(bmp.Height);
                    bmp.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                }
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, bmp.Width - 1, bmp.Height - 1);//画图片的边框线
                g.DrawString(strCode, new Font("宋体", 18), new SolidBrush(Color.Black), 8, 0);
                //Response. ; //字符串,字体 大小,字体色,位置
                bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                //打印这个图片
            }
        }

  • 相关阅读:
    Springboot中使用ibatis输出日志
    openssl生成iis需要的pfx格式的证书
    SpringBoot 默认日志
    Spring @Value 默认值
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成增删改查逻辑
    geomesa hbase geoserver
    在hyper-v中安装centos后配置网络
    linux命令
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成ResultMap
    Java 获取指定包下的所有类
  • 原文地址:https://www.cnblogs.com/zhhq/p/3103838.html
Copyright © 2020-2023  润新知