Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 源码示例

【VB.NET】验证图片生成

时 间:2008-10-16 08:15:15
作 者:fan0217   ID:3202  城市:绵阳
摘 要:验证图片生成
正 文:

CODE:


<%@ 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

 



Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助