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>

  • 相关阅读:
    sql server执行存储过程慢的问题
    Windows service
    moss网站模板的一些问题
    ACM题解报告——HD1012
    ACM题解报告——HD1496
    ACM题解报告——HD1253
    ACM题解报告——进制数取于余
    ACM题解报告——HD1058
    ACM题解报告——HD1548
    ACM解题报告HD1015
  • 原文地址:https://www.cnblogs.com/lierjie/p/3747851.html
Copyright © 2011-2022 走看看