欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

C#生成驗(yàn)證碼圖片的方法

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例為大家分享了C#生成驗(yàn)證碼圖片的具體代碼,供大家參考,具體內(nèi)容如下

/// <summary>
    /// 生成驗(yàn)證碼圖片
    /// </summary>
    /// <returns></returns>
    public byte[] GetVerifyCode()
    {
      int codeW = 80;
      int codeH = 40;
      int fontSize = 18;
      string chkCode = string.Empty;
      //顏色列表,用于驗(yàn)證碼、噪線、噪點(diǎn) 
      Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue };
      //字體列表,用于驗(yàn)證碼 
      string[] font = { "Times New Roman" };
      //驗(yàn)證碼的字符集,去掉了一些容易混淆的字符 
      char[] character = { '2', '3', '4', '5', '6', '8', '9', 'a', 'b', 'd', 'e', 'f', 'h', 'k', 'm', 'n', 'r', 'x', 'y', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' };
      Random rnd = new Random();
      //生成驗(yàn)證碼字符串 
      for (int i = 0; i < 4; i++)
      {
        chkCode += character[rnd.Next(character.Length)];
      }

      //創(chuàng)建畫布
      Bitmap bmp = new Bitmap(codeW, codeH);
      Graphics g = Graphics.FromImage(bmp);
      g.Clear(Color.White);
      //畫噪線 
      for (int i = 0; i < 1; i++)
      {
        int x1 = rnd.Next(codeW);
        int y1 = rnd.Next(codeH);
        int x2 = rnd.Next(codeW);
        int y2 = rnd.Next(codeH);
        Color clr = color[rnd.Next(color.Length)];
        g.DrawLine(new Pen(clr), x1, y1, x2, y2);
      }
      //畫驗(yàn)證碼字符串 
      for (int i = 0; i < chkCode.Length; i++)
      {
        string fnt = font[rnd.Next(font.Length)];
        Font ft = new Font(fnt, fontSize);
        Color clr = color[rnd.Next(color.Length)];
        g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 18, (float)0);
      }
      //將驗(yàn)證碼圖片寫入內(nèi)存流,并將其以 "image/Png" 格式輸出 
      MemoryStream ms = new MemoryStream();
      try
      {
        bmp.Save(ms, ImageFormat.Png);
        return ms.ToArray();
      }
      catch (Exception)
      {
        return null;
      }
      finally
      {
        g.Dispose();
        bmp.Dispose();
      }
    }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:WPF中NameScope的查找規(guī)則詳解

欄    目:C#教程

下一篇:C# BackgroundWorker使用教程

本文標(biāo)題:C#生成驗(yàn)證碼圖片的方法

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5064.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有