好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 12306動態(tài)驗證碼啟發(fā)之ASP.NET實現(xiàn)動態(tài)GIF驗證碼(附源碼)

12306動態(tài)驗證碼啟發(fā)之ASP.NET實現(xiàn)動態(tài)GIF驗證碼(附源碼)

熱門標簽:南昌自動外呼系統(tǒng)線路 云南外呼系統(tǒng)代理 海東防封電銷卡 上海市三維地圖標注 寧德防封版電銷卡 辦公用地圖標注網(wǎng)點怎么操作 西寧電銷外呼系統(tǒng)公司 聊城智能電銷機器人電話 安陸市地圖標注app

12306網(wǎng)站推出“彩色動態(tài)驗證碼機制”,新版驗證碼不但經(jīng)常出現(xiàn)字符疊壓,還不停抖動,不少人大呼“看不清”,稱“那個驗證碼,是畢加索的抽象畫么!”鐵總客服則表示:為了能正常購票只能這樣。而多家搶票軟件接近“報廢”,引發(fā)不少網(wǎng)友不滿的吐槽稱“太抽象太藝術(shù)了”。
以前做項目有時候也會用到驗證碼,但基本都是靜態(tài)的,這次也想湊湊12306的熱鬧。閑言少續(xù),切入正題,先上代碼。

實現(xiàn)方法:

 public void ShowCode()
    {
      //對象實例化
      Validate GifValidate = new Validate();

      #region 對驗證碼進行設(shè)置(不進行設(shè)置時,將以默認值生成)
      //驗證碼位數(shù),不小于4位
      GifValidate.ValidateCodeCount = 4;
      //驗證碼字體型號(默認13)
      GifValidate.ValidateCodeSize = 13;
      //驗證碼圖片高度,高度越大,字符的上下偏移量就越明顯
      GifValidate.ImageHeight = 23;
      //驗證碼字符及線條顏色(需要參考顏色類)
      GifValidate.DrawColor = System.Drawing.Color.BlueViolet;
      //驗證碼字體(需要填寫服務器安裝的字體)
      GifValidate.ValidateCodeFont = "Arial";
      //驗證碼字符是否消除鋸齒
      GifValidate.FontTextRenderingHint = false;
      //定義驗證碼中所有的字符(","分離),似乎暫時不支持中文
      GifValidate.AllChar = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";
      #endregion

      //輸出圖像(Session名稱)
      GifValidate.OutPutValidate("GetCode");
    }

調(diào)用主要方法:

public class Validate
  {
    public string AllChar = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";
    public Color DrawColor = Color.BlueViolet;
    public bool FontTextRenderingHint = false;
    public int ImageHeight = 0x17;
    private byte TrueValidateCodeCount = 4;
    protected string ValidateCode = "";
    public string ValidateCodeFont = "Arial";
    public float ValidateCodeSize = 13f;

    private void CreateImageBmp(out Bitmap ImageFrame)
    {
      char[] chArray = this.ValidateCode.ToCharArray(0, this.ValidateCodeCount);
      int width = (int) (((this.TrueValidateCodeCount * this.ValidateCodeSize) * 1.3) + 4.0);
      ImageFrame = new Bitmap(width, this.ImageHeight);
      Graphics graphics = Graphics.FromImage(ImageFrame);
      graphics.Clear(Color.White);
      Font font = new Font(this.ValidateCodeFont, this.ValidateCodeSize, FontStyle.Bold);
      Brush brush = new SolidBrush(this.DrawColor);
      int maxValue = (int) Math.Max((float) ((this.ImageHeight - this.ValidateCodeSize) - 3f), (float) 2f);
      Random random = new Random();
      for (int i = 0; i  this.TrueValidateCodeCount; i++)
      {
        int[] numArray = new int[] { (((int) (i * this.ValidateCodeSize)) + random.Next(1)) + 3, random.Next(maxValue) };
        Point point = new Point(numArray[0], numArray[1]);
        if (this.FontTextRenderingHint)
        {
          graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
        }
        else
        {
          graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
        }
        graphics.DrawString(chArray[i].ToString(), font, brush, (PointF) point);
      }
      graphics.Dispose();
    }

    private void CreateImageGif()
    {
      AnimatedGifEncoder encoder = new AnimatedGifEncoder();
      MemoryStream stream = new MemoryStream();
      encoder.Start();
      encoder.SetDelay(5);
      encoder.SetRepeat(0);
      for (int i = 0; i  10; i++)
      {
        Bitmap bitmap;
        this.CreateImageBmp(out bitmap);
        this.DisposeImageBmp(ref bitmap);
        bitmap.Save(stream, ImageFormat.Png);
        encoder.AddFrame(Image.FromStream(stream));
        stream = new MemoryStream();
      }
      encoder.OutPut(ref stream);
      HttpContext.Current.Response.ClearContent();
      HttpContext.Current.Response.ContentType = "image/Gif";
      HttpContext.Current.Response.BinaryWrite(stream.ToArray());
      stream.Close();
      stream.Dispose();
    }

    private void CreateValidate()
    {
      this.ValidateCode = "";
      string[] strArray = this.AllChar.Split(new char[] { ',' });
      int index = -1;
      Random random = new Random();
      for (int i = 0; i  this.ValidateCodeCount; i++)
      {
        if (index != -1)
        {
          random = new Random((i * index) * ((int) DateTime.Now.Ticks));
        }
        int num3 = random.Next(0x23);
        if (index == num3)
        {
          this.CreateValidate();
        }
        index = num3;
        this.ValidateCode = this.ValidateCode + strArray[index];
      }
      if (this.ValidateCode.Length > this.TrueValidateCodeCount)
      {
        this.ValidateCode = this.ValidateCode.Remove(this.TrueValidateCodeCount);
      }
    }

    private void DisposeImageBmp(ref Bitmap ImageFrame)
    {
      Graphics graphics = Graphics.FromImage(ImageFrame);
      Pen pen = new Pen(this.DrawColor, 1f);
      Random random = new Random();
      Point[] pointArray = new Point[2];
      for (int i = 0; i  15; i++)
      {
        pointArray[0] = new Point(random.Next(ImageFrame.Width), random.Next(ImageFrame.Height));
        pointArray[1] = new Point(random.Next(ImageFrame.Width), random.Next(ImageFrame.Height));
        graphics.DrawLine(pen, pointArray[0], pointArray[1]);
      }
      graphics.Dispose();
    }

    public void OutPutValidate(string ValidateCodeSession)
    {
      this.CreateValidate();
      this.CreateImageGif();
      HttpContext.Current.Session[ValidateCodeSession] = this.ValidateCode;
    }

    public byte ValidateCodeCount
    {
      get
      {
        return this.TrueValidateCodeCount;
      }
      set
      {
        if (value > 4)
        {
          this.TrueValidateCodeCount = value;
        }
      }
    }
  }

驗證碼效果:       -----下載源碼-----

以上就是實現(xiàn)ASP.NET的全部過程,還附有源碼,希望可以幫到大家更好地了解ASP.NET驗證碼的生成方法。

您可能感興趣的文章:
  • .NET生成動態(tài)驗證碼的完整步驟
  • .NET Core 2.0如何生成圖片驗證碼完整實例
  • ASP.NET Core使用SkiaSharp實現(xiàn)驗證碼的示例代碼
  • 一個簡單的ASP.NET驗證碼
  • .Net Core 下使用ZKWeb.System.Drawing實現(xiàn)驗證碼功能(圖形驗證碼)
  • .net實現(xiàn)動態(tài)驗證碼功能

標簽:崇左 南寧 贛州 汕尾 青海 衢州 洛陽

巨人網(wǎng)絡通訊聲明:本文標題《12306動態(tài)驗證碼啟發(fā)之ASP.NET實現(xiàn)動態(tài)GIF驗證碼(附源碼)》,本文關(guān)鍵詞  12306,動態(tài),驗證,碼啟,發(fā)之,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《12306動態(tài)驗證碼啟發(fā)之ASP.NET實現(xiàn)動態(tài)GIF驗證碼(附源碼)》相關(guān)的同類信息!
  • 本頁收集關(guān)于12306動態(tài)驗證碼啟發(fā)之ASP.NET實現(xiàn)動態(tài)GIF驗證碼(附源碼)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 成人看片黄app免费看软件| 国产又黄又爽又刺激| 日韩毛片免费线上观看| 日韩精品福利片午夜免费| 久久精品亚洲AV无码毛的用法| 晚上睡不着想看点害羞的app下载| 边吃奶边挵进去呻吟动态图| 黄色大全片| 被窝影视| 免费又黄又爽又大又色樱花| 高清欧美日韩一区二区欧美成人 | 浪荡超短裙长腿教师h| 美女不带戴套日出白浆| 强开小嫩苞一区二区三区图片| 亚洲熟女乱色一区二区三区丝袜 | 99热在线精品| 秘书的奶好大好紧| 欧美电影大尺度床戏r级五十度飞| baoyu113国产精品免费| 91精品国产丝袜白色高跟鞋商品种类 | 乖喷出来就舒服了H| 城中村老熟妇???| 动漫美女福利工本漫画18| 快穿肉文h| 美女h网站| 深耕陈雪全文阅读| 色女阁| 挠美女痒痒| 三级黄网| 精品中文字幕午夜| 美国一级性生活片| 午夜啪| 亚洲狼人社区| 久草视频福利在线| 亚洲精品一区国产欧美乱婬 | 竹菊影视国产精品| 嗯啊用力插| 爽?好?舒服?视频| 久久久久精品理论片| 色视频国产| h文小说网|