private string GetRandCode(int num)
{
string[] code = new string[]{"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","v","w","x","y","z"};
string vNum ="";
Random ran = new Random();
int iNum = 0;
for (int i = 1; i <= num; i++)
{
//while((iNum = Convert.ToInt32(code.Length*ran.NextDouble())) == code.Length)
//{
// iNum = Convert.ToInt32(code.Length*ran.NextDouble());
//}
iNum = ran.Next(0, code.Length);//哈哈 这句效率更高
vNum +=code[iNum];
}
return vNum;
}
private void DrawImage(string code)
{
Bitmap bp = new Bitmap(60,25);
Graphics ga = Graphics.FromImage(bp);
///设置画笔的输出模式
ga.SmoothingMode = SmoothingMode.HighSpeed;
Rectangle rc=new Rectangle(0,0,60,25);//定义一个矩形
ga.FillRectangle(new SolidBrush(Color.White), rc);//填充矩形
ga.DrawString(code, new Font("宋体", 16), new SolidBrush(Color.Red), rc);//在矩形内画出字符串
Response.ContentType = "image/jpeg";
//保存数据流
bp.Save(Response.OutputStream,ImageFormat.Jpeg);
bp.Dispose();
ga.Dispose();
}
- 顶
- 0