zoukankan
html css js c++ java
在ashx文件中读写session
代码片段
1
<%
@ WebHandler Language
=
"
C#
"
Class
=
"
codeImage
"
%>
2
3
using
System;
4
using
System.Web;
5
using
System.Web.SessionState;
6
using
System.Web.UI;
7
using
System.Drawing;
8
using
System.Drawing.Imaging;
9
public
class
codeImage :IHttpHandler,IRequiresSessionState
{
10
11
public
void
ProcessRequest (HttpContext context)
{
12
context.Response.ContentType
=
"
text/plain
"
;
13
DrawImage(Getcodes(
4
),context);
14
}
15
16
17
public
bool
IsReusable
{
18
get
{
19
return
false
;
20
}
21
}
22
public
string
[] Getcodes(
int
num)
23
{
24
string
[] codes
=
new
string
[num];
25
string
[] str
=
new
string
[]
{
"
0
"
,
"
1
"
,
"
2
"
,
"
3
"
,
"
4
"
,
"
5
"
,
"
6
"
,
"
7
"
,
"
8
"
,
"
9
"
}
;
26
Random rd
=
new
Random();
27
for
(
int
i
=
0
; i
<
num; i
++
)
28
{
29
codes[i]
=
str[rd.Next(
0
, str.Length)];
30
}
31
return
codes;
32
}
33
public
string
DrawImage(
string
[] codes,HttpContext context)
34
{
35
36
//
定义图片大小
37
Bitmap img
=
new
Bitmap(
50
,
18
);
38
Graphics g
=
Graphics.FromImage(img);
39
//
刷子,字体
40
Brush brush
=
new
SolidBrush(Color.Wheat);
41
Font f
=
new
Font(
"
Georgia
"
, 8f, FontStyle.Bold);
42
//
在图片上填充距形
43
g.FillRectangle(brush,
0
,
0
,
50
,
18
);
44
Brush abrush
=
new
SolidBrush(Color.Red);
45
Brush bbrush
=
new
SolidBrush(Color.Blue);
46
for
(
int
j
=
0
; j
<
codes.Length; j
++
)
47
{
48
SizeF sf
=
g.MeasureString(codes[j], f);
49
if
(j
%
2
==
0
)
50
{
51
g.DrawString(codes[j].ToString(), f, abrush,
3
+
j
*
sf.Width,
1
);
52
}
53
else
54
{
55
g.DrawString(codes[j].ToString(), f, bbrush,
3
+
j
*
sf.Width,
1
);
56
}
57
58
}
59
string
strcodes
=
""
;
60
for
(
int
i
=
0
; i
<
codes.Length; i
++
)
61
{
62
strcodes
+=
codes[i].ToString();
63
}
64
65
//
HttpContext.Current.Session["code"] = strcodes;
66
context.Session[
"
code
"
]
=
strcodes;
67
img.Save(context.Response.OutputStream, ImageFormat.Jpeg);
68
g.Dispose();
69
img.Dispose();
70
return
strcodes;
71
}
72
73
}
这里和大家分享和学习如何学IT!
查看全文
相关阅读:
PHP 如何阻止用户上传成人照片或者裸照
centos 从php5.1升级php到5.3的方法
用jQuery实现鼠标移动切换图片动画
利用表格实现大图轮播
css导行下拉动画
java script 基本函数
java script 数组去重两种方法
java script两个列表之间移动数据
JavaScript做个时间表 Date()
JS For 循环详解;棋盘放粮食 64;冒泡排序实例
原文地址:https://www.cnblogs.com/fuchifeng/p/1286316.html
最新文章
L2-011 玩转二叉树 (中前序推层序
3655: 网络禁用语
堆排序
二维数组遍历
上楼梯问题,斐波那契数列
二叉树的遍历,递归和非递归
列出路径下所有文件,以及子目录下所有文件,用递归
编写一个程序,将 d:java 目录下的所有.java 文件复制到 d:jad 目录下,并将原来文件的扩展名从.java 改为.jad。
编写一个程序,将 a.txt 文件中的单词与 b.txt 文件中的单词交替合并到 c.txt 文件中,a.txt 文件中的单词用回车符分隔,b.txt 文件中用回车或空格进行分隔。
查询各部门中高于部门平均工资的人员,人数及该部门的平均工资
热门文章
读取文件中某个字符串前面的内容,两种方法
单链表的反转
js报TypeError $(...) is null错误,jquery失效的原因及解决办法
php 单引号 和双引号区别
jQuery学习之prop和attr的区别
http://www.techtarget.com.cn/
MongoDB 学习一,关于表结构
MongoDB 入门 -- 表结构设计
navicat for mysql 连接远程数据库服务器
Linux 下如何进入 MySQL 命令行
Copyright © 2011-2022 走看看