国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
生成驗證碼
1首先建一個aspx頁面代碼如下
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Web.AjaxPage.OtherRequest
{
    public partial class VialCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //設(shè)置不緩存此頁
            Response.AppendHeader("pragma", "no-cache");
            Response.AppendHeader("Cache-Control", "no-cache, must-revalidate");
            Response.AppendHeader("expires", "0");
            Random rand = new Random();
            //獲取隨機字符
            string str = GetRandString(4);
            Session["nowcodecode"] = str;//保存驗證碼
            //創(chuàng)建畫板
            Bitmap image = new Bitmap(63, 25);
            Graphics g = Graphics.FromImage(image);
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.InterpolationMode = InterpolationMode.Low;
            //g.CompositingMode = CompositingMode.SourceOver;
            //g.CompositingQuality = CompositingQuality.HighQuality;
            g.CompositingQuality = CompositingQuality.HighSpeed;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //繪制漸變背景
            Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
            Brush brushBack = new LinearGradientBrush(rect, Color.FromArgb(rand.Next(150, 256), 255, 255), Color.FromArgb(255, rand.Next(150, 256), 255), rand.Next(90));
            g.FillRectangle(brushBack, rect);
            //繪制干擾曲線
            for (int i = 0; i < 2; i++)
            {
                Point p1 = new Point(0, rand.Next(image.Height));
                Point p2 = new Point(rand.Next(image.Width), rand.Next(image.Height));
                Point p3 = new Point(rand.Next(image.Width), rand.Next(image.Height));
                Point p4 = new Point(image.Width, rand.Next(image.Height));
                Point[] p = { p1, p2, p3, p4 };
                Pen pen = new Pen(Color.Gray, 1);
                g.DrawBeziers(pen, p);
            }
            //逐個繪制文字
            for (int i = 0; i < str.Length; i++)
            {
                string strChar = str.Substring(i, 1);
                int deg = rand.Next(-15, 15);
                float x = (image.Width / str.Length / 2) + (image.Width / str.Length) * i;
                float y = image.Height / 2;
                //隨機字體大小
                Font font = new Font("Consolas", rand.Next(16, 24), System.Drawing.FontStyle.Regular);
                SizeF size = g.MeasureString(strChar, font);
                Matrix m = new Matrix();
                //旋轉(zhuǎn)
                m.RotateAt(deg, new PointF(x, y), MatrixOrder.Append);
                //扭曲
                m.Shear(rand.Next(-10, 10) * 0.03f, 0);
                g.Transform = m;
                //隨機漸變畫筆
                Brush brushPen = new LinearGradientBrush(rect, Color.FromArgb(rand.Next(0, 256), 0, 0), Color.FromArgb(0, 0, rand.Next(0, 256)), rand.Next(90));
                g.DrawString(str.Substring(i, 1), font, brushPen, new PointF(x - size.Width / 2, y - size.Height / 2));
                g.Transform = new Matrix();
            }
            g.Save();
            Response.ContentType = "image/jpeg";
            Response.Clear();
            Response.BufferOutput = true;
            image.Save(Response.OutputStream, ImageFormat.Jpeg);
            g.Dispose();
            image.Dispose();
            Response.Flush();
        }
        //獲取隨機數(shù)
        private string GetRandString(int len)
        {
            //string s = "0123456789";
            string s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string str = "";
            Random r = new Random();
            for (int i = 0; i < len; i++)
            {
                str += s.Substring(r.Next(s.Length), 1);
            }
            return str;
        }
    }
}
2顯示驗證碼圖片的地方
 <td id="td1"><span id="vcodetxt"></span>驗證碼:</td>
                <td>
                    <input type="text" class="input" id="txtcode" style="width:55px;"  />
                </td>
                <td>
                    <img alt="刷新驗證碼" src="AjaxPage/OtherRequest/VialCode.aspx" id="codeimage" onclick="this.src=this.src+'?'" />
                </td>

 
3怎么校驗驗證碼是否輸入正確
當(dāng)然產(chǎn)生的時候就存入session然后登陸的時候和session比較就OK啦

 
4注意:onclick="this.src=this.src+'?'"這個是為了點擊圖片的時候從新生成

 
5效果如下
 
 

 

 
 
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C# 生成驗證碼
Photoshop從頭學(xué)起?(01-84集)
Asp.net(C#)實現(xiàn)驗證碼功能 - 流浪的狗 - 博客園
頁面添加驗證碼功能
ASP.NET MVC實現(xiàn)網(wǎng)站驗證碼功能(中)
《JSP生成驗證碼源程序》
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服