zoukankan      html  css  js  c++  java
  • 不出现重复数字,带干扰的验证码

    View Code
     1             Bitmap map = new Bitmap(200,80);
    2 Graphics g = Graphics.FromImage(map);
    3 g.Clear(Color.White);
    4 Random r = new Random();
    5 string codestr = null;
    6 for (int i = 0; i < 4; i++)
    7 {
    8 string rdnum=r.Next(10).ToString ();
    9 if (codestr != null)
    10 {
    11 if (codestr.IndexOf(rdnum) >= 0)
    12 {
    13 i--;
    14 continue;
    15 }
    16 }
    17 codestr += rdnum;
    18 }
    19 g.DrawString(codestr, new Font("宋体", 40), Brushes.Red, new PointF(8, 8));
    20 //添加噪音线
    21 for (int i = 0; i < 20; i++)
    22 {
    23 int x1 = r.Next(map.Width);
    24 int y1 = r.Next(map.Height);
    25 int x2 = r.Next(map.Width);
    26 int y2 = r.Next(map.Height);
    27 g.DrawLine(new Pen(Brushes.Plum), x1, y1, x2, y2);
    28 }
    29 //添加噪音点
    30 for (int i = 0; i < 500; i++)
    31 {
    32 map.SetPixel(r.Next(map.Width), r.Next(map.Height), Color.FromArgb(r.Next(1)));
    33 }
    34 MemoryStream ms = new MemoryStream();
    35 map.Save (ms,System .Drawing .Imaging .ImageFormat .Jpeg );
    36 this .pictureBox1 .Image =Image .FromStream (ms);
  • 相关阅读:
    python二维数组切片
    [转载]MIPS常用指令及实例
    使用vim编程步骤
    数组指针和指针数组
    线程基础
    顶层const和底层const
    递归调用
    输出流
    C++代码规范
    I/O流
  • 原文地址:https://www.cnblogs.com/pfcan66/p/2345105.html
Copyright © 2011-2022 走看看