asp.net Generate picture Verification code class

Source: Internet
Author: User
Tags tostring
Asp.net| Verification Code

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Drawing;
Using System.Drawing.Imaging;
Using System.Drawing.Text;
public class RandPic:System.Web.UI.Page
{
<summary>
Verification code number
</summary>
public int Num = 0;
<summary>
Picture width
</summary>
public int imgwidth=60;
<summary>
Picture height
</summary>
public int imgheight=30;
Public Randpic ()
{
}
<summary>
Constructors
</summary>
<param name= "Rndnum" > Authentication code number </param>
Public randpic (int rndnum)
{
if (Rndnum > 0)
{
Num = Rndnum;
}
}
<summary>
Generate pictures
</summary>
public void Make ()
{
Bitmap map=new Bitmap (imgwidth,imgheight);
Graphics GP = graphics.fromimage (map);
Gp. Clear (Color.White);
Font ft = new Font ("Arial black", 13);
PointF Point =new PointF (3,3);
Gp. DrawString (Num.tostring (), FT, Brushes.burlywood, point);
Gp. Save ();
Map. Save (Response.outputstream, imageformat.gif);
}
}
Call Page showrand.aspx
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using _14base;
public partial class Manager_logrnd:randpic
{
protected void Page_Load (object sender, EventArgs e)
{
This. Num = 8888;
HttpCookie cookie = new HttpCookie ("Userrnd", Rnd. ToString ());
RESPONSE.COOKIES.ADD (cookie);
This. Make ();
}
}



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.