using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing.Imaging; using System.Drawing; using System.IO; public partial class image:System.Web.UI.Page ... {protectedvoidPage_Load(objectsender,EventArgse)...{stringtmp=RndNum(4);//HttpCookiea=newHttpCookie("ImageV",tmp);//Response.Cookies.Add(a);//2006-3-31郭挺上面二行是用COOKIE来存下面用SESSION保存Session["ImageV"]=tmp;this.ValidateCode(tmp);}privatevoidValidateCode(stringVNum)...{BitmapImg=null;Graphicsg=null;MemoryStreamms=null;intgheight=VNum.Length*12;Img=newBitmap(gheight,25);g=Graphics.FromImage(Img);//背景颜色g.Clear(Color.White);//文字字体Fontf=newFont("ArialBlack",12);//文字颜色SolidBrushs=newSolidBrush(Color.Gray);g.DrawString(VNum,f,s,3,3);ms=newMemoryStream();Img.Save(ms,ImageFormat.Jpeg);Response.ClearContent();Response.ContentType="image/Jpeg";Response.BinaryWrite(ms.ToArray());g.Dispose();Img.Dispose();Response.End();}privatestringRndNum(intVcodeNum)...{stringVchar="1,2,3,4,5,6,7,8,9,0";//A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Zstring[]VcArray=Vchar.Split(newChar[]...{','});stringVNum="";inttemp=-1;Randomrand=newRandom();for(inti=1;i<VcodeNum+1;i++)...{if(temp!=-1)...{rand=newRandom(i*temp*unchecked((int)DateTime.Now.Ticks));}//9intt=rand.Next(9);if(temp!=-1&&temp==t)...{returnRndNum(VcodeNum);}temp=t;VNum+=VcArray[t];}returnVNum;}}