编程语言

img iwebsms

生成图象验证码函数

发表于2004/9/28 19:12:00  741人阅读

    '生成图象验证码函数

    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
阅读全文
0 0

相关文章推荐

img
取 消
img