Copy codeThe Code is as follows:
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. Drawing2D;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Bitmap bmp = new Bitmap (50, 25 );
Graphics g = Graphics. FromImage (bmp );
SolidBrush sb = new SolidBrush (getColor ());
G. DrawString (CheckNumber (), new Font ("", 16), sb, 0, 0 );
Bmp. Save (Response. OutputStream, System. Drawing. Imaging. ImageFormat. Gif );
}
Public static string CheckNumber ()
{
String checkcode = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
Int len = 4;
String tmpstr = "";
Int iRandNum;
Random rnd = new Random ();
For (int I = 0; I <len; I ++)
{
IRandNum = rnd. Next (checkcode. Length );
Tmpstr + = checkcode [iRandNum];
}
Return tmpstr;
}
Private Color getColor ()
{
Random r = new Random ();
Return Color. FromArgb (r. Next (256), r. Next (256), r. Next (256 ));
}
}