private void CreateImage (string checkcode)
{
int iwidth = (int) (CHECKCODE.LENGTH * 15);
System.Drawing.Bitmap image = New System.Drawing.Bitmap (iwidth, 25);
Graphics g = graphics.fromimage (image);
G.clear (Color.White);
Define Color
Color[] C = {Color.black,color.red,color.darkblue,color.green,color.orange,color.brown,color.darkcyan, Color.purple};
Define font string[] Font = {"Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "Song Body"};
Random rand = new Random ();
Random output Noise Point
for (int i=0;i<50;i++)
{
int x = rand. Next (image. Width);
int y = rand. Next (image. Height);
G.drawrectangle (New Pen (Color.lightgray, 0), x,y,1,1);
}
Output CAPTCHA characters for different fonts and colors
for (int i=0;i<checkcode.length;i++)
{
int cindex = rand. Next (7);
int findex = rand. Next (5);
Font f = new System.Drawing.Font (Font[findex], System.Drawing.FontStyle.Bold);
Brush B = new System.Drawing.SolidBrush (C[cindex]);
int ii=4;
if ((i+1)%2==0)
{
ii=2;
}
g.DrawString (Checkcode.substring (i,1), F, B, 3+ (I*12), ii);
}
Draw a border
G.drawrectangle (New Pen (color.black,0), 0,0,image. Width-1,image. HEIGHT-1);
//Output to browser
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
image. Save (Ms,system.drawing.imaging.imageformat.jpeg);
response.clearcontent ();
Response.ContentType = "Image/jpeg";
Response.BinaryWrite (Ms. ToArray ());
g.dispose ();
image. Dispose ();
}