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