''生成圖象驗證碼函數
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