Asp.net implements waveform distortion and color brushless newest Verification Code

Source: Internet
Author: User

There are many examples of the Asp.net verification code on the Internet, but there are few articles on the refresh and waveform distortion, and the examples are almost hard to find, so I collected some materials 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:Copy to ClipboardReference: [www.bkjia.com] // <summary>
/// Sine curve Wave distorted image (Edit By 51aspx.com)
/// </Summary>
/// <Param name = "srcBmp"> image path </param>
/// <Param name = "bXDir"> True for distortion </param>
/// <Param name = "nMultValue"> the amplitude multiple of the waveform. The larger the waveform is, the higher the distortion is. Generally, it is 3. </param>
/// <Param name = "dPhase"> start phase of the waveform, value range: [0-2 * PI) </param>
/// <Returns> </returns>
Public System. Drawing. Bitmap TwistImage (Bitmap srcBmp, bool bXDir, double dMultValue, double dPhase)
{
System. Drawing. Bitmap destBmp = new Bitmap (srcBmp. Width, srcBmp. Height );

// Fill the bitmap background in white
System. Drawing. Graphics graph = System. Drawing. Graphics. FromImage (destBmp );
Graph. FillRectangle (new SolidBrush (System. Drawing. Color. White), 0, 0, destBmp. Width, destBmp. Height );
Graph. Dispose ();

Double dBaseAxisLen = bXDir? (Double) destBmp. Height: (double) destBmp. Width;

For (int I = 0; I <destBmp. Width; I ++)
{
For (int j = 0; j <destBmp. Height; j ++)
{
Double dx = 0;
Dx = bXDir? (PI2 * (double) j)/dBaseAxisLen: (PI2 * (double) I)/dBaseAxisLen;
Dx + = dPhase;
Double dy = Math. Sin (dx );

// Obtain the color of the current vertex
Int nOldX = 0, nOldY = 0;
NOldX = bXDir? I + (int) (dy * dMultValue): I;
NOldY = bXDir? J: j + (int) (dy * dMultValue );

System. Drawing. Color color = srcBmp. GetPixel (I, j );
If (nOldX> = 0 & nOldX <destBmp. Width
& Amp; nOldY & gt; = 0 & amp; nOldY <destBmp. Height)
{
DestBmp. SetPixel (nOldX, nOldY, color );
}
}
}

Return destBmp;
} I have found a lot of complicated articles about the problem of refreshing the image. Later 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 example source code: 1-100122103Q0.rar

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.