生成图象验证码函数
发表于:2007-06-30来源:作者:点击数:
标签:
'生成图象验证码函数 Sub ValidateCode(ByVal VNum As String) Dim Img As System.Drawing.Bitmap Dim g As Graphics Dim ms As System.IO.MemoryStream 'gheight为图片宽度,根据字符长度自动更改图片宽度 Dim gheight As Integer = Int(Len(VNum) * 11.5) '
'生成图象验证码函数
Sub ValidateCode(ByVal VNum As String)
Dim Img As System.Drawing.Bitmap
Dim g As Graphics
Dim ms As System.IO.MemoryStream
'gheight为图片宽度,根据字符长度自动更改图片宽度
Dim gheight As Integer = Int(Len(VNum) * 11.5)
'创建一个宽度已定,高度为20的图像
Img = New Bitmap(gheight, 20)
g = Graphics.FromImage(Img)
'在矩形内绘制字串(字串,字体,画笔颜色,左上x.左上y)
g.DrawString(VNum, (New Font("宋体", 12)), (New SolidBrush(Color.Blue)), 3, 3)
ms = New System.IO.MemoryStream
Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Response.ClearContent() '需要输出图象信息 要修改HTTP头
Response.ContentType = "image/Png"
Response.BinaryWrite(ms.ToArray())
g.Dispose()
Img.Dispose()
Response.End()
End Sub
原文转自:http://www.ltesting.net