zoukankan
html css js c++ java
httphandler生成验证图
<%
@ WebHandler Language
=
"
C#
"
Class
=
"
image
"
%>
using
System;
using
System.Web;
using
System.Drawing;
public
class
image : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{
public
void
ProcessRequest (HttpContext context)
{
context.Response.ContentType
=
"
text/gif
"
;
Bitmap b
=
new
Bitmap(
200
,
60
);
Graphics g
=
Graphics.FromImage(b);
g.FillRectangle(
new
SolidBrush(Color.White),
0
,
0
,
200
,
60
);
Font font
=
new
Font(FontFamily.GenericSansSerif,
48
, FontStyle.Bold, GraphicsUnit.Pixel);
Random r
=
new
Random();
string
letters
=
"
ABCDEFGHIJKMNPQRSTUVWXYX
"
;
string
letter;
System.Text.StringBuilder s
=
new
System.Text.StringBuilder();
for
(
int
x
=
0
; x
<
5
; x
++
)
{
letter
=
letters.Substring(r.Next(
0
, letters.Length
-
1
),
1
);
s.Append(letter);
g.DrawString(letter, font,
new
SolidBrush(Color.Black), x
*
38
, r.Next(
0
,
15
));
}
Pen linePen
=
new
Pen(
new
SolidBrush(Color.Black),
2
);
for
(
int
x
=
0
; x
<
6
; x
++
)
{
g.DrawLine(linePen,
new
Point(r.Next(
0
,
199
), r.Next(
0
,
59
)),
new
Point(r.Next(
0
,
199
), r.Next(
0
,
59
)));
}
b.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
context.Session[
"
aaa
"
]
=
s.ToString();
context.Response.End();
}
public
bool
IsReusable
{
get
{
return
false
;
}
}
}
<img src="image.ashx" />
查看全文
相关阅读:
什么才是java的基础知识?
Java的背景、影响及前景
设计模式分类
关于日期及日期格式转换的记录
添加同名工具后台验证后不跳转且保留用户输入的数值
案件讨论回复中出现把多个附件当成一个评论显示,导致分页出错
指令发布详情弹窗实现“取消”按钮
最大间隔分离超平面的唯一性完整证明
CART算法与剪枝原理
Spark MLlib学习
原文地址:https://www.cnblogs.com/zwl12549/p/964728.html
最新文章
20180315 代码错题(3)
20180315 代码错题(2)
20180315 代码错题(1)
大数处理问题
输出菱形
K进制数
IP判断
字符逆序
母牛的故事
Minesweeper
热门文章
走迷宫
【程序员面试宝典读书笔记】位域
【程序员面试宝典读书笔记】指针数组和数组指针
【程序员面试宝典读书笔记】sizeof和strlen的区别
【程序员面试宝典读书笔记】n&(n-1)
复指数形式的傅里叶级数
统计学生提交作业情况
基于模糊集理论的一种图像二值化算法
Java中的main()方法详解
Java基础语法学习知识
Copyright © 2011-2022 走看看