zoukankan      html  css  js  c++  java
  • 网站验证码

     1//直接复制进去就可以用了
     2
     3public System.Web.UI.WebControls.Image verifyNumber=new System.Web.UI.WebControls.Image();
     4   private void Page_Load(object sender, System.EventArgs e)
     5   { 
     6    string tmp = RndNum(Convert.ToInt16(6));
     7    Session["verify"]=tmp;
     8    ValidateCode(tmp);
     9   }
    10   private void ValidateCode(string VNum) 
    11   {
    12    Bitmap Img=null;
    13    Graphics g=null;
    14    MemoryStream ms=null
    15    int gheight=VNum.Length*9;
    16    Img=new Bitmap(gheight,18);
    17    g=Graphics.FromImage(Img);
    18    //背景颜色
    19    g.Clear(Color.WhiteSmoke);
    20    //文字字体
    21    Font f=new Font("Tahoma",9);
    22    //文字颜色
    23    SolidBrush s=new SolidBrush(Color.Red);
    24    g.DrawString(VNum,f,s,3,3);
    25    ms=new MemoryStream();
    26    Img.Save(ms,ImageFormat.Jpeg);
    27    Response.ClearContent(); 
    28    Response.ContentType="image/Jpeg";
    29    Response.BinaryWrite(ms.ToArray());
    30    g.Dispose();
    31    Img.Dispose();
    32    Response.End();
    33   }
    34   private string RndNum(int VcodeNum)
    35   {
    36    string MaxNum="";
    37    string MinNum="";
    38    for(int i=0;i    {
    39     MaxNum=MaxNum+"9";
    40    }
    41    MinNum=MaxNum.Remove(0,1);
    42    Random rd=new Random();   
    43    string VNum=Convert.ToString(rd.Next(Convert.ToInt32(MinNum),Convert.ToInt32(MaxNum)));
    44    return VNum;
    45   }
    46 
    47
  • 相关阅读:
    uva 11294 Wedding
    uvalive 4452 The Ministers’ Major Mess
    uvalive 3211 Now Or Later
    uvalive 3713 Astronauts
    uvalive 4288 Cat Vs. Dog
    uvalive 3276 The Great Wall Game
    uva 1411 Ants
    uva 11383 Golden Tiger Claw
    uva 11419 SAM I AM
    uvalive 3415 Guardian Of Decency
  • 原文地址:https://www.cnblogs.com/shengel/p/676057.html
Copyright © 2011-2022 走看看