zoukankan      html  css  js  c++  java
  • C#生成验证码

     1   public static byte[] GetVerifyCode(string codeStr)
     2         {
     3             Random r = new Random();
     4             Bitmap btBitmap = new Bitmap(80, 30);
     5 
     6             Graphics g = Graphics.FromImage(btBitmap);
     7             g.Clear(Color.White);
     8             //画干扰线
     9             for (int i = 0; i < 20; i++)
    10             {
    11                 int x1 = r.Next(btBitmap.Width);
    12                 int y1 = r.Next(btBitmap.Height);
    13                 int x2 = r.Next(btBitmap.Width);
    14                 int y2 = r.Next(btBitmap.Height);
    15                 g.DrawLine(new Pen(Color.Black),x1,y1,x2,y2 );
    16             }
    17             //画干扰点
    18             for (int i = 0; i < 100; i++)
    19             {
    20                 int x1 = r.Next(btBitmap.Width);
    21                 int y1 = r.Next(btBitmap.Height);
    22                 btBitmap.SetPixel(x1,y1,Color.Aqua);
    23             }
    24             //画图
    25             g.DrawString(codeStr, new Font("宋体", 16), new SolidBrush(Color.Red), 0, 0);
    26             MemoryStream ms = new MemoryStream();
    27             btBitmap.Save(ms, ImageFormat.Gif);
    28             return ms.ToArray();
    29         }
  • 相关阅读:
    隔离级别
    分析Hello2代码
    正则表达式
    Filter and servlet
    部署描述符
    Annotation
    LDAP and Implementation
    Restful levels and Hateoas
    servlet injection analysis
    隔离级别
  • 原文地址:https://www.cnblogs.com/niceskyfly/p/4977959.html
Copyright © 2011-2022 走看看