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
这段代码定义了一个名为ValidateCode的子程序,接收一个字符串参数VNum。通过创建图像、绘制字符串、保存到内存流等操作,最终将验证码图片以PNG格式输出,最后释放资源并结束响应。
4285

被折叠的 条评论
为什么被折叠?



