zoukankan
html css js c++ java
最近写的一个验证码.
<%
@ Import Namespace
=
"
System.Web
"
%>
<%
@ Import Namespace
=
"
System.Drawing
"
%>
<%
@ Import Namespace
=
"
System.Drawing.Drawing2D
"
%>
<
script runat
=
"
server
"
language
=
"
c#
"
>
void
Page_Load(Object Src, EventArgs E)
{
CreateCheckCodeImage();
}
private
string
GenerateCheckCode()
{
int
number;
char
code;
string
checkCode
=
String.Empty;
System.Random random
=
new
Random();
int
count
=
4
;
//
random.Next(3,6);
for
(
int
i
=
0
; i
<
count; i
++
)
{
number
=
random.Next();
if
(number
%
2
==
0
)
code
=
(
char
)(
'
0
'
+
(
char
)(number
%
10
));
else
code
=
(
char
)(
'
A
'
+
(
char
)(number
%
26
));
checkCode
+=
code.ToString();
}
Session[
"
CheckCode
"
]
=
checkCode;
return
checkCode;
}
private
static
Font[] fonts
=
new
Font[]
{
new
System.Drawing.Font(
"
Arial
"
,
20
, System.Drawing.FontStyle.Regular),
new
System.Drawing.Font(
"
Arial
"
,
24
, System.Drawing.FontStyle.Italic),
new
System.Drawing.Font(
"
Batang
"
,
20
,System.Drawing.FontStyle.Regular),
new
System.Drawing.Font(
"
Batang
"
,
26
,System.Drawing.FontStyle.Italic),
new
System.Drawing.Font(
"
Courier
"
,
28
,System.Drawing.FontStyle.Regular),
new
System.Drawing.Font(
"
Courier
"
,
26
,System.Drawing.FontStyle.Italic),
new
System.Drawing.Font(
"
Arial
"
,
20
,System.Drawing.FontStyle.Bold)
}
;
private
static
Brush[] brushs
=
new
Brush[]
{
//
new HatchBrush(HatchStyle.Percent30, color, Color.White),
new
HatchBrush(HatchStyle.Percent40, color, Color.White),
//
new HatchBrush(HatchStyle.Percent25, color, Color.White),
//
new HatchBrush(HatchStyle.SmallCheckerBoard, color, Color.White)
}
;
private
static
Color color
=
Color.Black;
private
void
CreateCheckCodeImage()
{
string
codeStr
=
GenerateCheckCode();
int
height
=
40
;
int
witdh
=
30
*
codeStr.Length;
Bitmap image
=
new
Bitmap(witdh, height);
Graphics g
=
Graphics.FromImage(image);
Random rnd
=
new
Random();
Brush brush
=
brushs[rnd.Next(brushs.Length)];
g.FillRectangle(brush,
0
,
0
, witdh, height);
Font font
=
new
System.Drawing.Font(
"
Arial
"
,
24
, System.Drawing.FontStyle.Regular);
LinearGradientBrush b
=
new
LinearGradientBrush(
new
Point(
0
,
0
),
new
Point(
40
,
100
), color,color);
for
(
int
i
=
0
; i
<
codeStr.Length; i
++
)
{
Point p
=
new
Point(i
*
25
+
rnd.Next(
-
3
,
5
), rnd.Next(
-
3
,
5
));
g.DrawString(codeStr[i].ToString(), fonts[rnd.Next(fonts.Length)], b, p);
}
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());
}
</
script
>
风云
查看全文
相关阅读:
hdu 4503(湫湫系列故事——植树节)
JAVA里面如何让一个线程死亡或结束
c 语言static
TUXEDO与ORACLE数据库的互连
关于使用PRO*C编程的一些简单说明和例子
atoi函数
我的顶级Java工具名单
Tuxedo动态配置命令 tmconfig用法总结
main(argc,argv) 中的参数
pro c中varchar类型变量的arr函数是做什么用?
原文地址:https://www.cnblogs.com/lovebanyi/p/657074.html
最新文章
数据结构与算法
从Delphi的发展目睹数据库开发的演变
走了,就不再回来
摩托车坏了
衷心祝愿她们!
衷心祝愿她们!
中国程序员为什么应读“名著”
这段时间会很忙
走了,就不再回来
民主党派信息管理系统[有软件截图]
热门文章
昨天晚上,女孩子进我们宿舍的门转贴
汇编实习二(屏幕显示)
hdu1895(最小长方形)
hdu 2037(今年暑假不AC)
汇编实习一()
hdu 1062 Text Reverse (STL栈)
hdu 2072(单词数)
hdu 2099(整除的尾数)
刻骨铭心
选择不相交区间(贪心:求不相交区间最多个数)
Copyright © 2011-2022 走看看