No need to copy the google waveform distortion color Asp.net verification code-Zookeeper

Source: Internet
Author: User

No need to copy the google waveform distortion color Asp.net Verification Code favorites
There are many examples of Asp.net verification codes on the Internet. Some time ago, my "Asp.net brushless New Chinese verification codes implemented by 51aspx" was reprinted by many websites, however, there are very few articles about no refreshing and waveform distortion, and the examples are almost hard to find. So I collected some information and wrote an example for free. The main features are as follows:

:

Refreshing: that is, the common functions of websites such as "cannot see clearly, click to change" and "Change Verification Code". A js script is ready!
Waveform distortion: similar to the google verification code, this is more effective to prevent the verification code from being broken by robots. You can set the specific distortion level (the sine curve Wave distorted image generates the waveform filter effect ), adding parameters can also be changed to those of msn. Let's just put it apart!

Color: The character colors are random.
Case sensitivity: it is also random. You can modify the case sensitivity for input convenience.
Note details: each parameter has a detailed description, which is easy to use.

To display the distortion effect, the default font size is 40 pixels, which can be modified by yourself.

Distorted source code:

1/** // <summary>
2 // sine Wave distorted image (Edit By 51aspx.com)
3 /// </summary>
4 /// <param name = "srcBmp"> image path </param>
5 /// <param name = "bXDir"> True if distorted </param>
6 // <param name = "nMultValue"> the amplitude multiple of the waveform. The larger the waveform is, the higher the distortion is. Generally, it is 3. </param>
7 // <param name = "dPhase"> start phase of the waveform, value range: [0-2 * PI) </param>
8 /// <returns> </returns>
9 public System. Drawing. Bitmap TwistImage (Bitmap srcBmp, bool bXDir, double dMultValue, double dPhase)
10 {
11 System. Drawing. Bitmap destBmp = new Bitmap (srcBmp. Width, srcBmp. Height );
12
13 // fill the bitmap background in white
14 System. Drawing. Graphics graph = System. Drawing. Graphics. FromImage (destBmp );
15 graph. FillRectangle (new SolidBrush (System. Drawing. Color. White), 0, 0, destBmp. Width, destBmp. Height );
16 graph. Dispose ();
17
18 double dBaseAxisLen = bXDir? (Double) destBmp. Height: (double) destBmp. Width;
19
20 for (int I = 0; I <destBmp. Width; I ++)
21 {
22 for (int j = 0; j <destBmp. Height; j ++)
23 {
24 double dx = 0;
25 dx = bXDir? (PI2 * (double) j)/dBaseAxisLen: (PI2 * (double) I)/dBaseAxisLen;
26 dx + = dPhase;
27 double dy = Math. Sin (dx );
28
29 // obtain the color of the current vertex
30 int nOldX = 0, nOldY = 0;
31 nOldX = bXDir? I + (int) (dy * dMultValue): I;
32 nOldY = bXDir? J: j + (int) (dy * dMultValue );
33
34 System. Drawing. Color color = srcBmp. GetPixel (I, j );
35 if (nOldX> = 0 & nOldX <destBmp. Width
36 & nOldY> = 0 & nOldY <destBmp. Height)
37 {
38 destBmp. SetPixel (nOldX, nOldY, color );
39}
40}
41}
42
43 return destBmp;
44}
45
I have found a lot of complicated articles about the problem of no refreshing, and then I came up with a simple method.

A piece of js Code is done. I don't know if other people have any comments? Welcome

Download sample source code

 

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.