zoukankan      html  css  js  c++  java
  • 验证码(二)

    这是一个方法  只需要在前面调用就可以额! 

    public static void DisplayPic()
        {
            string msg = GetRandomString();
            HttpContext.Current.Session["code"] = msg; ;
            Bitmap image = new Bitmap(50, 20);
            Graphics g = Graphics.FromImage(image);
            g.Clear(Color.White);

            Random random = new Random();

            for (int i = 0; i < 20; i++)
            {
                int x1 = random.Next(image.Width);
                int y1 = random.Next(image.Height);
                int x2 = random.Next(image.Width);
                int y2 = random.Next(image.Height);

                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }
            Font font = new Font("宋体", 12);
            SolidBrush brush = new SolidBrush(Color.Blue);
            PointF point = new PointF(2, 2);
            g.DrawString(msg, font, brush, point);

            g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            HttpContext.Current.Response.BinaryWrite(ms.ToArray());
        }

     protected void Page_Load(object sender, EventArgs e)
        {
            Common.DisplayPic();

        }

  • 相关阅读:
    linux配置Java环境变量(详细)
    linux下的挂载点和分区是什么关系
    VNC的安装与配置
    Linux下的字符集问题
    Freemarker学习中遇到的问题
    ABAP- INCLUDE Zxxx IF FOUND.
    ABAP读取工单状态 STATUS_READ
    WIN7系统设置wifi
    201702-增强记
    20170301 Excel 分多个sheet 导出
  • 原文地址:https://www.cnblogs.com/weihengblogs/p/2799069.html
Copyright © 2011-2022 走看看