All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0高级数据处理之使用参数_.net资料_编程技术
Delphi使用ADO连接SQL Server 2000数据库
ASP.NET从零起步设计网站全过程(11)_[Asp.Net教程]
C#教程:多线程简介
PHP技巧:PHP如何禁止图片文件的被盗链_[PHP教程]
如何让javascript,操作Cookie_php资料_编程技术
做网站的一般企业网站表结构信息_[SQL Server教程]
在ASP.NET,2.0中建立站点导航层次_[Asp.Net教程]
分清SQL,Server中易混淆的数据类型_[SQL,Server教程]
实用:使用PHP脚本修改Linux或Unix系统口令_php资料_编程技术
Reading number is top 10 pictures
9.3阅兵全景图2-英雄连队梯队和外国方阵梯队
Chinese paper-cut grilles art appreciation1
9.3阅兵全景图3-外国方阵梯队和坦克方阵梯队
Plump, too plump!1
男人,就要活出棱角
Discharge accidentally Actresses by the breast1
Wear bikinis cock
China's first snake village3
中国的十元人民币的秘密
30 beautiful school beauty1
Download software ranking
VeryCD电驴(EasyMule) V1.1.9 Build09081
Boxer vs Yellow4
SP4 for SQL2000
Red cliff
仙剑奇侠传98硬盘WINXP版
Boxer Classic video2
Boxer's Top ten classic battle10
天龙八部最新服务端
Be there or be square
电车之狼R
delv published in(发表于) 2014/1/10 6:32:10 Edit(编辑)
收藏一段小的.net下的验证码片段_[Asp.Net教程]

收藏一段小的.net下的验证码片段_[Asp.Net教程]

收藏一段小的.net下的验证码片段_[Asp.Net教程]

收藏一段小的.net下的验证码片段,以供以后参考。


protected void Page_Load(object sender, EventArgs e)
{
//先产生数字串
string checkCode = this.CreateRandomCode(6);
//用session保存
Session["CheckCode"] = checkCode;
//作图
CreateImage(checkCode);

}
private void CreateImage(string checkCode)
{
System.Drawing.Bitmap image = new System.Drawing.Bitmap(Convert.ToInt32(Math.Ceiling((decimal)(checkCode.Length * 14))), 22);
Graphics g = Graphics.FromImage(image);


try
{

Random random = new Random();
g.Clear(Color.AliceBlue);

for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);


g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}


Font font = new System.Drawing.Font("Comic Sans MS", 12, System.Drawing.FontStyle.Bold);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, new SolidBrush(Color.Red), 2, 2);



for (int i = 0; i < 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);


image.SetPixel(x, y, Color.FromArgb(random.Next()));
}


g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);


System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}


public string CreateRandomCode(int codeCount)
{
string allChar = "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[] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1;


Random rand = new Random();
for (int i = 0; i < codeCount; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(36);
if (temp != -1 && temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.