C # Generate Authenticode instance

Source: Internet
Author: User

Common generation Code Instance encapsulation:

/// <summary>///Generating a memory bitmap/// </summary>/// <param name= "Code" ></param>/// <returns></returns> Public StaticBitmap GetCode ( out stringCode) {    intImgWidth = the; intImgHeight = +; //get random charactersCode = Datetimehelper.getcode_ran (4); //List of colors for verification codes, noise lines, noise pointscolor[] color ={color.black, color.red, Color.Blue, Color.green, Color.orange, Color.brown, Color.brown, Color.DarkBlue}; //font list, for verification code    string[] Font = {"Times New Roman","MS Mincho","Book Antiqua","Gungsuh","PMingLiU","Impact" }; Bitmap BMP=NewBitmap (ImgWidth, imgheight); Graphics g=graphics.fromimage (BMP);    G.clear (Color.White); Random Rnd=NewRandom (); //Draw Noise Line     for(inti =0; I <Ten; i++)    {        intX1 =Rnd.        Next (ImgWidth); intY1 =Rnd.        Next (ImgHeight); intx2 =Rnd.        Next (ImgWidth); inty2 =Rnd.        Next (ImgHeight); Color CLR=Color[rnd. Next (color.        Length)]; G.drawline (NewPen (CLR), x1, y1, x2, y2); }    //draw a Captcha string     for(inti =0; i < code.length; i++)    {        stringFNT =Font[rnd. Next (font.        Length)]; Font ft=NewFont (FNT, -); Color CLR=Color[rnd. Next (color.        Length)]; g.DrawString (Code[i]. ToString (), FT,NewSolidBrush (CLR), (floatI +, (float)8); }    //Draw Noise points     for(inti =0; I < -; i++)    {        intx =Rnd. Next (BMP.        Width); inty =Rnd. Next (BMP.        Height); Color CLR=Color[rnd. Next (color.        Length)]; Bmp.    SetPixel (x, Y, CLR); }    //explicitly releasing resources//bmp. Dispose ();G.dispose (); returnbmp;}/// <summary>///generate bitmap, output to response stream/// </summary>/// <param name= "Response" ></param>/// <param name= "Code" ></param> Public Static voidGetCode (Httpresponsebase Response, out stringCode) {Code=string.    Empty; Bitmap bit= GetCode ( outCode); ////Clear the page output cache, set the page without caching    //Response.Buffer = true; //Response.ExpiresAbsolute = DateTime.Now.AddMilliseconds (0); //Response.Expires = 0; //Response.CacheControl = "No-cache"; //Response.appendheader ("Pragma", "No-cache");response.clearcontent (); Bit.    Save (Response.outputstream, imageformat.png); Response.ContentType="Image/png"; //Freeing Resourcesbit. Dispose ();}

C # Generate Authenticode instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.