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();

        }

  • 相关阅读:
    python随机生成
    socket、tcp、http
    TCP三次握手和http过程
    iOS多线程的初步研究(十)-- dispatch同步
    dispatch队列
    IOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
    UIWebView 自定义网页中的alert和confirm提示框风格
    dispatch_semaphore
    app内购提示,您已购买此商品,但未下载
    单例的写法
  • 原文地址:https://www.cnblogs.com/weihengblogs/p/2799069.html
Copyright © 2011-2022 走看看