zoukankan      html  css  js  c++  java
  • 一般处理程序结合gdi生成简单验证码

    using (Bitmap bitmap=new Bitmap(100,40))
    {
    using (Graphics g=Graphics.FromImage(bitmap))
    {
    //生成验证码
    string s = code();
    g.DrawString(s, new Font("黑体", 20), Brushes.Red, 0, 0);
    bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    }

     //改变bitmap的颜色  循环遍历

    for (int j = 0; j < 100; j++)
    {
    for (int i = 0; i < 40; i++)
    {
    bitmap.SetPixel(j, i, Color.White);
    }
    }

    //生成随机数的方法

    private string code()
    {
    string s = "";
    Random rd = new Random();
    for (int i = 0; i < 4; i++)
    {
    int a = rd.Next(0, 10);
    s += a.ToString();
    }
    return s;
    }

    前台调用以及javascript

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script>
    window.onload = function () {
    document.getElementById("img").onclick = function () {
    this.src = 'huatu.ashx';
    }
    }
    </script>
    </head>
    <body>
    <img src="huatu.ashx" alt="验证码" id="img" title="点击更换" style="cursor:pointer" />
    </body>
    </html>

    html页内利用jQuery控制验证码的大小

    <script src="jquery-1.8.3.js"></script>
    <script>
    $(function () {
    $('#img').mouseover(function () {
    $(this).css({ "width": '120px', "height": "60px" });
    }).mouseout(function () {
    $(this).css({ "width": '', "height": "" })
    });
    })
    </script>

  • 相关阅读:
    Win7安装netbeans 找不到JDK
    MyEclipse10 中设置Jquery提醒,亲测可用
    Property 'submit' of object #<HTMLFormElement> is not a function
    JSP Unable to compile class for JSP
    JSP session过期时间(小记)
    JSP乱码(小记)
    JS 正则表达式基础
    CSS 盒子模型
    Cmder--window开发者神器!!
    encodeURI和encodeURIComponent两者的区别
  • 原文地址:https://www.cnblogs.com/lierjie/p/3747851.html
Copyright © 2011-2022 走看看