首页 > 编程 > .NET > 正文

Asp.net生成图片验证码类

2024-07-10 13:06:07
字体:
来源:转载
供稿:网友

using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.drawing;
using system.drawing.imaging;
using system.drawing.text;
public class randpic:system.web.ui.page
{
    /// <summary>
    /// 验证码数字
    /// </summary>
    public int num = 0;
    /// <summary>
    /// 图片宽度
    /// </summary>
    public int imgwidth=60;
    /// <summary>
    /// 图片高度
    /// </summary>
    public int imgheight=30;
    public randpic()
    {
    }
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="rndnum">验证码数字</param>
    public randpic(int rndnum)
    {
        if (rndnum > 0)
        {
            num = rndnum;
        }
    }
    /// <summary>
    /// 生成图片
    /// </summary>
    public void make()
    {
        bitmap map=new bitmap(imgwidth,imgheight);
        graphics gp = graphics.fromimage(map);
        gp.clear(color.white);
        font ft = new font("arial black", 13);
        pointf point =new pointf(3,3);
        gp.drawstring(num.tostring(), ft, brushes.burlywood, point);
        gp.save();
        map.save(response.outputstream, imageformat.gif);
    }
}
调用页 showrand.aspx
using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using _14base;
public partial class manager_logrnd : randpic
{
    protected void page_load(object sender, eventargs e)
    {
        this.num = 8888;
        httpcookie cookie = new httpcookie("userrnd", rnd.tostring());
        response.cookies.add(cookie);
        this.make();
    }
}

 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表