using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

public partial class Include_VerifyCode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Random rnd = new Random();
        string rndnum;
        rndnum = rnd.Next(10, 99) + rnd.Next(10, 99).ToString();
        this.Session["Verify"] = rndnum;

        Bitmap MyBitmap = null;
        Graphics g = null;
        string ShowStr = (string)this.Session["Verify"];
        SizeF SF;
        int Width;
        int Height;
        Font MyFont = new Font("Small Fonts", 11, FontStyle.Bold);
        MemoryStream MS;

        if (ShowStr == null || ShowStr == "")
            ShowStr = "error";
        try
        {
            try
            {
                MyBitmap = new Bitmap(2, 2, PixelFormat.Format24bppRgb);
                g = Graphics.FromImage(MyBitmap);
                SF = g.MeasureString(ShowStr, MyFont);
                Width = (int)SF.Width;
                Height = (int)SF.Height;
                g.Dispose();
                MyBitmap.Dispose();
                MyBitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                g = Graphics.FromImage(MyBitmap);
                g.FillRectangle(new SolidBrush(Color.FromArgb(245, 255, 225)), new Rectangle(0, 0, Width, Height));
                g.DrawString(ShowStr, MyFont, new SolidBrush(Color.Red), 0, 0);
                MS = new MemoryStream();
                MyBitmap.Save(MS, System.Drawing.Imaging.ImageFormat.Gif);
                this.Response.ClearContent();
                this.Response.ContentType = "image/gif";
                this.Response.BinaryWrite(MS.ToArray());
                this.Response.End();
            }
            catch (Exception ee)
            {
                this.Response.Write(ee.ToString());
            }
        }
        finally
        {
            if (ShowStr != null)
                g.Dispose();
            if (MyBitmap == null)
                MyBitmap.Dispose();
        }
			
    }
}
