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();
    }
}
新聞熱點
疑難解答
圖片精選