|
-
-
- <%@ WebHandler Language="VB" Class="GetValidateImage" %>
- Imports System
- Imports System.Web
- Imports System.Data
- Imports System.Configuration
- Imports System.Collections
- Imports System.Web.Security
- Imports System.Web.UI
- Imports System.Web.UI.WebControls
- Imports System.Web.UI.WebControls.WebParts
- Imports System.Web.UI.HtmlControls
- Imports System.Drawing
- Imports System.Drawing.Imaging
- Imports System.IO
- Public Class GetValidateImage : Implements IHttpHandler
-
- Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
- Dim number As String = Trim(context.Request.QueryString("number"))
- Dim gheight As Integer = Int(Len(number) * 11.5)
- 'gheight为图片宽度,根据字符长度自动更改图片宽度
- Dim img As New Bitmap(gheight, 20)
- Dim g As Graphics = Graphics.FromImage(img)
- g.DrawString(number, (New Font("Arial", 10)), (New SolidBrush(Color.Blue)), 3, 3) '在矩形内绘制字串(字串,字体,画笔颜色,左上x.左上y)
- Dim ms As New MemoryStream()
- Img.Save(ms, ImageFormat.Png)
- context.Response.ClearContent() '需要输出图象信息 要修改HTTP头
- context.Response.ContentType = "image/Png"
- context.Response.BinaryWrite(ms.ToArray())
- g.Dispose()
- Img.Dispose()
- context.Response.End()
- End Sub
-
- Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
- Get
- Return False
- End Get
- End Property
- End Class
-
复制代码 |
|