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();
}
posted on 2006-12-06 21:29  Hawk_Yuan  阅读(184)  评论(0编辑  收藏  举报