温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:唐唐企业管理网站源码
当前文件:
TangCompany/Manager/CheckImage.aspx.cs,打开代码结构图
TangCompany/Manager/CheckImage.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Drawing; 12
using System.Text; 13
using System.Drawing.Drawing2D; 14
using System.Drawing.Imaging; 15
16
public partial class Manager_CheckImage : System.Web.UI.Page 17
{ 18
protected void Page_Load(object sender, EventArgs e) 19
{ 20
CheckImage(GetCode(5)); 21
} 22
//返回验证码的位数 23
protected string GetCode(int i) { 24
25
Random ran = new Random(); 26
string strCode = string.Empty; 27
string[] str ={ "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", "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" }; 28
for (int j = 0; j < i; j++) { 29
30
strCode += str[ran.Next(str.Length)]; 31
32
} 33
Session["CheckCode"] = strCode; 34
return strCode; 35
36
} 37
protected void CheckImage(string nCode) { 38
39
Random ran=new Random(); 40
Bitmap img = new Bitmap(70, 24); 41
Graphics g = Graphics.FromImage(img); 42
g.Clear(System.Drawing.Color.White); 43
for (int i = 0; i < 30; i++) { 44
45
g.DrawLine(Pens.Gainsboro, new Point(ran.Next(img.Width), ran.Next(img.Height)), new Point(ran.Next(img.Height),ran.Next(img.Width))); 46
47
} 48
g.DrawRectangle(Pens.Green, new Rectangle(0, 0, 69, 23)); 49
Font font = new Font("Arail", 12, FontStyle.Bold); 50
g.DrawString(nCode, font, Brushes.Black, new Point(5, 4)); 51
System.IO.MemoryStream ms = new System.IO.MemoryStream(); 52
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); 53
Response.ClearContent(); 54
Response.ContentType = "Image/Gif"; 55
Response.BinaryWrite(ms.ToArray()); 56
57
} 58
} 59





}
}