Picture verification code

xiaoxiao2021-04-05  253

/// /// graphics verification code generation page ///abraxas@163.com/// Reference mode: (N is the number of verification code bits) /// Using system; use system.collections; useing system.ComponentModel; use system.data; useing system.drawing; useing system.Web; use system.Web.SessionState; Using system.Web.ui; use system.web.ui.webcontrols; using system.web.ui.htmlcontrols; using system.io;

Namespace Abraxas {///

/// Abraxasvalcode's summary description. /// public class abraxasvalcode: system.Web.ui.page {private void page_load (Object sender, system.eventargs e) {// Place user code here to initialize page string valcode = randomstring (int. Parse (Request.QueryString ["n"])); session.add ("Valcode", Valcode; DrawImage (Valcode);

/ / Generate random string private string randomstring (int bit) {string charS = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, G, H, I, J, K, L, M, N, O, P, Q, R, Y, T, U, V, W, X, Y, Z "; String [] Chararray = Chars.Split ( ','); String result = ""; random rdm = new random (); for (int i = 0; i

// Draw the verification code into graphical void drawimage (String Valcode) {// Generate bitmap bitmap bmp = new bitmap (Valcode.length * 16, 25); graphics g = graphics.fromage (bmp); try {g. Clear (color.white);

// Define color and font set color [] c = {color.red, color.green, color.navy, color.darkcyan, color.blue, color.purple}; string [] fonts = {"Microsoft Sans Serif", "Times New Roman", "Lucida Console", "Arial", "Verdana"}

// Draw background grid Pen P = new pen (color.lightgray, 0); int y = 5; do {g.drawline (p, 0, y, bmp.width, y); y = 5;} while (Y

// Draw the border G. DrawRectangle (P, 0, 0, bmp.width-1, bmp.height-1);

// output to the page MemoryStream ms = new MemoryStream (); bmp.Save (ms, System.Drawing.Imaging.ImageFormat.Gif); Response.Cache.SetNoStore (); Response.ClearContent (); Response.ContentType = "image / Gif "; response.binaryWrite (ms.toarray ()); response.end ();} finally {g.dispose (); bmp.dispose ();}}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void initializecomponent () {this.load = new system.eventhandler (this.page_load);} #ENDREGON}}

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

New Post(0)