More and more websites now like to develop verification codes, which can be basically achieved in all languages. Today I am writing a C!
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Drawing. imaging;
Using system. Drawing. drawing2d;
// Create a bitmap object
Public void randomnumber ()
{
Bitmap newbitmap = new Bitmap (36,16, pixelformat. format32bppargb );
// Create a drawing surface based on the previously created bitmap object
Graphics G = graphics. fromimage (newbitmap );
// Fill the rectangle with the specified color
G. fillrectangle (New solidbrush (color. White), new rectangle ));
// Create a font object
Font textfont = new font ("Times New Roman", 10 );
// Create a rectanglef structure to specify a region
Rectanglef rectangle = new rectanglef (0, 0, 36, 16 );
// Create a random number object
Random RD = new random ();
// Obtain a random number
Int valationno = 1000 + RD. Next (8999 );
// Fill the area of the rectangle specified by the rectanglef structure with the specified color
G. fillrectangle (New solidbrush (color. burlywood), rectangle );
// Fill in the rectangle filled above with the random number generated above
G. drawstring (valationno. tostring (), textfont, new solidbrush (color. Blue), rectangle );
// Save the created bitmap to the specified path
Newbitmap. Save (server. mappath ("IMG") + "\ img.gif", imageformat. GIF );
}
After the image is generated, you can introduce the image address on the foreground page!