[CODE]private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.Expires = -1;
string str=RndNum(4);
Response.Cookies["yan"].Value=str;
char[] ch=str.ToUpper().ToCharArray();
Random rand =new Random();
int iii=rand.Next(8);
while (iii<1) iii=rand.Next(8);
Bitmap yan = (Bitmap) Bitmap.FromFile(Server.MapPath("images/y"+iii+".jpg"));
Bitmap img=new Bitmap(73,28);
int x1=rand.Next(220),y1=rand.Next(270);
Rectangle re1=new Rectangle(x1,y1,73,28);
Rectangle re2=new Rectangle(0,0,73,28);
Graphics g= Graphics.FromImage(img);
g.DrawImage(yan,re2,re1,GraphicsUnit.Pixel);
// g.DrawImage(yan,0,0,100,30);
SolidBrush s = new SolidBrush( Color.Black);
for(int i=0;i<=3;i++)
{
int k=rand.Next(18);
while (k<13) k=rand.Next(16);
x1=6+i*15;
if("34579".IndexOf(ch[i].ToString())>-1) y1=rand.Next(20-k)-2;
else y1=rand.Next(24-k)-2;
Font f = new Font("Georgia",k);
g.DrawString(ch[i].ToString(),f,s,x1,y1);
}
img.Save(Response.OutputStream,ImageFormat.Jpeg);
g.Dispose();
img.Dispose();
yan.Dispose();
}
private string RndNum(int VcodeNum)
{
string Vchar ="0,1,2,3,4,5,6,7,8,9";
string[] VcArray = Vchar.Split(',') ;
string VNum = "";
int temp = -1 ;
Random rand =new Random();
for ( int i = 1 ; i < VcodeNum+1 ; i++ )
{
if ( temp != -1)
{
rand =new Random(i*temp*unchecked((int)DateTime.Now.Ticks));
}
int t = rand.Next(9);
if (temp != -1 && temp == t)
{
return RndNum( VcodeNum );
}
temp = t ;
VNum += VcArray[t];
}
return VNum ;
}[/CODE]
几个背景图