Img.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
Response.ClearContent(); //需要输出图象信息 要修改HTTP头
Response.ContentType="image/Png";
Response.BinaryWrite(ms.ToArray());
g.Dispose();
Img.Dispose();
Response.End();
}
///
/// 生成验证码
///
/// 校验码长度
/// 返回校验码
private string GenerateCheckCode(int CodeLength)
{
string Vchar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";
string[]VcArray=Vchar.Split(new char[]{','}); //将字符串生成数组
string VNum ="";
for(byte i=1;i<=CodeLength;i++)
{
Random ro=new Random();
VNum+=VcArray[(int)(35*ro.NextDouble())]; //数组一般从0开始读取,所以这里为35*Rnd
}
return VNum;
}
您可能感兴趣的文章: