验证码的生成

C#->ASP.NET

private string GetPicStr(string _picChars,int _length)
{
  string wPicStr="";
  int wRandInt;
  Random wRandom=new Random();
  for(int i;i<_length;i++)
  {
     wRandInt=wRandom.Next(_picChars.Length);
     wPicStr+=_picChar[wRandInt];
  }
  return wPicStr;
}

private void Page_Load(object sender,System.EventArgs e)
{
  string wPicChars="0123456789";
  string wPicStr=GetPicStr(wPicChars,4);
  string wFontName=" 新明细体";
  int wFontSize=11;
  int wWidth=10*wPicStr.Length;
  int wHeight=15;
  Color wBColor=Color.White;
  Color wFColor=Color.Red;
  Session["CheckPicStr"]=wPicStr;
  Font wFont=new Font(wFontName,wFontSize,FontStyle.Body);
  Bitmap wBitmap=new Bitmap(wWidth,wHeight,PixelFormat.Format32bppArgb);
  Graphics wGraphics=Graphics.FromImage(wBitmap);
  Rectangle wRect=new Rectangle(0,0,wWidth,wHeight);
  wGraphics.FillRectangle(new SolidBrush(wBColor),wRect);
  wGraphics.DrawString(wPicstr,wFont,new SolidBrush(wFColor)2,2);
  MemoryStream wMStream=new MemoryStream();
  wBitmap.Save(wMStream,ImageFormat.Gif);
  wGraphics.Dispose();
  wBitmap.Dispose();
  Response.ClearContent();
  Response.ContentType="image/GIF";
  Response.BinaryWrite(wMStream.ToArray());
  Response.End();
}

转载于:https://www.cnblogs.com/Hawk-Hong/archive/2006/12/06/584639.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值