关于生成图片验证码
大家帮我看看是哪里不对了?我对着教程一步一步写的代码一样就是不出效果。程序代码:
using System.Drawing; //引用命名空间 using System.Drawing.Imaging; protected void Page_Load(object sender, EventArgs e) { string yzm = Ran(); Response.Write(yzm); Session["yzm"] = yzm; //随机数写入 int width = 70; //图片的长度 int heith = 20; //图片的高度 string fontcolor = "White"; //字体颜色 float fontsize = 12; //字体的大小 string font = "宋体"; //字体 Bitmap img = new Bitmap(width, heith); //一个图片框 Graphics g = Graphics.FromImage(img); //把图片装截入 g.DrawString(yzm, new Font(font, fontsize), new SolidBrush(Color.FromName(fontcolor)), 10, 2); img.Save(Response.OutputStream, ImageFormat.Jpeg); } private static string Ran() { string RanString = "123456789"; int i = 0; string a = ""; Random Ran = new Random(); while (i <= 3) { a += Ran.Next(RanString.Length); i++; } return a; }