Method for generating a verification code picture for a background image

xiaoxiao2021-03-06  108

Parameter Description:

Sourcefile: background picture file

Text: Text to display

public void MakeCheckImage (string sourceFile, string text) {Response.Clear (); try {// picture Bitmap sImage = new Bitmap (sourceFile); // codes FIG Bitmap wImage = new Bitmap (100,30, System.Drawing .Imaging.pixelformat.format24bppRGB); Graphics wg = graphics.fromimage (wimage); wg.clear (color.white); wg.drawstring (Text, New Font ("Verdana", 18), New Solidbrush (Color.Black) , 0, 0); wg.save (); // make graphics. Graphics g = graphics.fromimage (simage); int x; // Temporary variable int y; // Memachment variable INT W = 100; // Verification The width INT H = 30; // verify the height INT Al; // alpha Int rl; // red INT GL; // Green INT BL; // Blue // Start Draw FOR (x = 1; x < w; x ) {for (y = 1; y 0) RL - = 50; IF (GL - 50> 0) GL - = 50; IF (BL - 50> 0) BL - = 50; g.dra Wellipse (New Solidbrush), x, y, 1, 1);}} g., 1, 1);}} g.save (); simage.SoutputStream JPEG); wg.dispose (); g.dispose (); simage.dispose (); wiMage.dispose ();} catch (exception e) {response.write (E.MESSAGE);} response.end (); }

转载请注明原文地址:https://www.9cbs.com/read-124617.html

New Post(0)