程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> asp.net實現驗證碼

asp.net實現驗證碼

編輯:.NET實例教程

#region 實現一個驗證碼的類

  public class ValidateCode

  {

  private Bitmap validateimage;

  private Graphics g;

  public ValidateCode()

  {

  validateimage = new Bitmap(120, 30, PixelFormat.Format24bppRgb);

  g = Graphics.FromImage(validateimage);

  }

  public void DrawValidateCode(Page e, string i)

  {

  g.DrawString(i, new Font("黑體",16,FontStyle.Bold),new SolidBrush(Color.White),new PointF(2,4));

  g.FillRectangle(new LinearGradIEntBrush(new Point(0,0), new Point(120,30), Color.FromArgb(0,0,0,0),Color.FromArgb(255,255,255,255)),0,0,120,30);

  //validateimage.Save(e.OutputStream, ImageFormat.Jpeg);

  g.Save();

  MemoryStream ms=new MemoryStream();

  validateimage.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);

  e.Response.ClearContent();

  e.Response.ContentType="image/gif";

  e.Response.BinaryWrite(ms.ToArray());

  e.Response.End();

  //validateimage.Save(e.MapPath("NumImage/ValidateImage.gif"), ImageFormat.Gif);

  //e.End();

  }

  }

  

  #endregion

  private void MakeValidateCode()

  {

  char[] s = new char[]{"0","1", "2","3","4","5","6","7","8","9","a"

  ,"b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"

  ,"r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G"

  ,"H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W"

  ,"X","Y","Z"};

  string num = "";

  Random r = new Random();

  for(int i = 0; i < 5; i++)

       }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved