- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.IO;
-
- public partial class Capcha : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- Color brushColor = System.Drawing.Color.Green;
-
-
- Bitmap objBitmap = new System.Drawing.Bitmap(100, 30);
-
-
- Graphics objGraphics = System.Drawing.Graphics.FromImage(objBitmap);
- objGraphics.Clear(Color.Transparent);
-
-
- Font objFont = new Font("Times New Roman", 14, FontStyle.Regular);
-
- string inputNumberString = "";
-
- Random r = new Random();
-
- int a = r.Next(99, 999);
- int b = r.Next(99, 999);
-
- int c = a + b;
-
- inputNumberString = a.ToString() + " + " + b.ToString() + " = ";
-
-
- Session["CaptchaValue"] = c.ToString();
-
- SolidBrush myBrush = new SolidBrush(brushColor);
-
- objGraphics.DrawString(inputNumberString, objFont, myBrush, 3, 3);
-
-
- Response.ContentType = "image/png";
-
- System.IO.MemoryStream mem = new MemoryStream();
-
-
- objBitmap.Save(mem, ImageFormat.Png);
-
-
- mem.WriteTo(Response.OutputStream);
-
-
- objFont.Dispose();
-
-
- objGraphics.Dispose();
-
-
- objBitmap.Dispose();
- }
- }