附加码生产程序

发布时间: 2007-05-21 09:40    作者: 未知    来源: 未知    浏览:    评论

<%@ Page Language="VB" debug=true%>
<%@ Import Namespace="system"%>
<%@ Import Namespace="system.Drawing"%>
<%@ Import Namespace="system.Drawing.Imaging"%>
<%@ Import Namespace="system.IO"%>
<script runat="server">
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' 附加码生产程序 附加码生产程序 附加码生产程序 附加码生产程序 ''
'' ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' ''
'' 为 教 师 节 献 礼 ''
'' ''
'' 今天要写附加码验证程序,本来想偷懒,可在网上搜索了好久没有一断满意的代码, ''
''索性就自己写了这段代码,运行后觉得效果不错!不敢私藏,特拿来给大家分享!以此感 ''
''谢CSDN、以及在CSDN的高手们!! ''
'' ''
'' ''
'' 望大家发表你尊贵的意见! ''
'' ''
'' dudu8686@126.com ''
'' 2004年9月10日 ''
'' ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub page_load(byval sender As Object,byval E As EventArgs)
'Font_Size'字体大小 intrger
'Char_Number'验证码的位数 intrger
'BackgroundColor'背景颜色 十六进制数的字符串
dim My_Stream as MemoryStream=Get_Images(20,50,"#000000")
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=int(Font_Size*1.5)+Font_Size*Char_Number'这个数字在调用页面需要,你要自己算出明确的数值 注意注意注意注意!!!!!
dim image_h as integer=int(2.5*Font_Size)'这个数字在调用页面需要,你要自己算出明确的数值 注意注意注意注意!!!!!

dim Temp_Bitmap as Bitmap'封装GDI+位图
dim Temp_Graphics as Graphics'封装GDI+绘图面
dim Color_Back as Color=ColorTranslator.FromHtml(BackgroundColor)'背景颜色

Temp_Bitmap = new Bitmap(image_w, 5*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 Char_Number-1
dim Show_Str as string=getChar()'要显示为图像的字符
Sesson_Company=Sesson_Company & Show_Str
dim Show_Str_Font_Size as integer=Int(3 * Rnd()+(Font_Size-2))'字体随机大小 下波动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)'定义文本格式(字体,字号,粗体)
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))'绘出字符 '绘字符的Y方向下波动+4
next
session("imagenumber")=LCase(trim(Sesson_Company))'保存到session便于调用的页面比较 '不区分大小写

Font_Size=Font_Size*4
image_h=int(2.5*Font_Size)
Temp_Graphics.DrawString("欢", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+0*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("迎", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+1*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("使", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+2*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("用", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+3*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("! ", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+4*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("请", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+5*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("按", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+6*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("F5", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+7*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("键", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+8*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4
Temp_Graphics.DrawString("!", new Font(getFont1(),Int(3 * Rnd()+(Font_Size-2)),FontStyle.Bold), new SolidBrush(ColorTranslator.FromHtml(getColor())), int(Font_Size/5+9*1.3*Font_Size), int(image_h/4)+Int(image_h*0.125 * Rnd()+image_h*0.08))'绘出字符 '绘字符的Y方向下波动+4

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

function getChar() as string'获得随机字符 0-9 a-z A-Z
Dim Char_array(5)
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
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)
return "#" & Hex(int_a) & Hex(int_b) & Hex(int_c)
end function

function getFont() as string'获得随机字体
Dim font_array(7)
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)
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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 注 意 '
' ' '
'把所有的代码保存为:ChrToImages.aspx --------->可以直接运行看效果 '
'在其它页面的调用方法:<img width=image_w height=image_h src=http://www.webasp.net/article/14/"ChrToImages.aspx" align="absmiddle"> '
'image_w、image_h,你要自己算出明确的数值,并注意session("imagenumber") '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>

TAG

Smile Big Smile Surprise Stick out tongue Wink Sad Tongue Tied Indifferent Crying Embarrassed Cool Angry Angel Devil [8-|] [:#] [:-*] [:^)] [<:o)] [|-)] Yes Beer Left Hug Music Star Time Snail Pizza Automobile Umbrella Computer Storm [mo] [8o|] [^o)] [+o(] [*-)] [8-)] Coffee No Drinks [Z] Right Hug Cake Broken Heart Gift Wilted Flower Movie Dog Idea Sleep Email Travel Paradise
呢称:

加粗 斜体 下划线 链接 图片 代码 邮件地址 引用 列表

最多只能输入100个字符

Tags

SQL 数据库 asp.net C# XML 控件 .NET教程 程序 事件 数据 安全 代码 Server 客户端 验证 数据库专栏 接口 文件 Oracle DataSet 函数 DataGrid 问题 .net return C#语言 JavaScript 服务 IIS 对象 语句 windows 继承 时间 web.config 设计 开发 参数 变量 解决 字符 ADO.net 环境 VB.Net语言 web 异常 工具 服务器 计算 实例 OLEDB Application VB Word WebService insert asp net 安装 记录

精华推荐

更多

精品下载

更多