Winform-based GDI verification code and winformgdi-Based Drawing

Source: Internet
Author: User

Winform-based GDI verification code and winformgdi-Based Drawing

Main functions: Click the verification code to change and enter the verification code to log on.

 

You need to import the namespace System. Drawing;

Generates five random strings:

1 Random random = new Random (); 2 // generate 5 Random strings 3 str = null; 4 for (int I = 0; I <5; I ++) 5 {6 int j = random. next (64, 90); 7 str = str + (char) j; 8}

Draw string

1 // Create Image 2 Bitmap bmp = new Bitmap (); 3 // create a GDI object 4 Graphics g = Graphics. fromImage (bmp); 5 // looping string 6 for (int I = 0; I <str. length; I ++) 7 {8 Point p = new Point (I * 20, 0); 9 // random font 10 string [] fonts = {"", "", "", "subordinate", "",}; 11 // random Color 12 Color [] colors = {Color. red, Color. aquamarine, Color. blue, Color. yellow, Color. yellowGreen}; 13 // draw a string of 14 GB. drawString (str [I]. toString (), new Font (fonts [random. next (0, fonts. length)], 20, FontStyle. bold), new SolidBrush (colors [random. next (0, colors. length)]), p); 15}

The effect is as follows:

At this time, we are adding some lines:

1        for (int i = 0; i < 20; i++)2             {3                 Point p1 = new Point(random.Next(0, bmp.Width), random.Next(0, bmp.Height));4                 Point p2 = new Point(random.Next(0, bmp.Width), random.Next(0, bmp.Height));5                 g.DrawLine(new Pen(Color.Green), p1, p2);6             }

Draw some pixels:

1 // draw the pixel 2 for (int I = 0; I <500; I ++) 3 {4 Point p = new Point (random. next (0, bmp. width), random. next (0, bmp. height); 5 bmp. setPixel (p. x, p. y, Color. black); 6}

This is basically the case. There is no technical content!

Source Code address: http://pan.baidu.com/s/1gdgYqpt

Related Article

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.