zoukankan      html  css  js  c++  java
  • 生成圖片的驗證碼

       private string GetRandCode(int num)
            {
            string[] code = new string[]{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
            string vNum ="";
            Random ran = new Random();
            int iNum = 0;
            for (int i = 1; i <= num; i++)
            {
                //while((iNum = Convert.ToInt32(code.Length*ran.NextDouble())) == code.Length)
                //{
                //    iNum = Convert.ToInt32(code.Length*ran.NextDouble());
                //}
                iNum = ran.Next(0, code.Length);//哈哈 这句效率更高
                vNum +=code[iNum];
            }
            return vNum;
            }

            private void DrawImage(string code)
            {
            Bitmap bp = new Bitmap(60,25);
            Graphics ga = Graphics.FromImage(bp);
            ///设置画笔的输出模式
            ga.SmoothingMode = SmoothingMode.HighSpeed;

            Rectangle rc=new Rectangle(0,0,60,25);//定义一个矩形
            ga.FillRectangle(new SolidBrush(Color.White), rc);//填充矩形
            ga.DrawString(code, new Font("宋体", 16), new SolidBrush(Color.Red), rc);//在矩形内画出字符串
            Response.ContentType = "image/jpeg";

            //保存数据流
            bp.Save(Response.OutputStream,ImageFormat.Jpeg);
            bp.Dispose();
            ga.Dispose();
            } 

     
    0
  • 相关阅读:
    Finder那点事
    mysql基础综述(四)
    【算法编程】过河问题
    CodeForces 7D Palindrome Degree 字符串hash
    语音信号短时域分析之预处理(三)
    sqlite学习笔记7:C语言中使用sqlite之打开数据库
    cpu真实占用率检測工具
    Mediator Design Pattern 中介者模式
    POJ-3984-迷宫问题-BFS(广搜)-手写队列
    HDU 4858 项目管理
  • 原文地址:https://www.cnblogs.com/accumulater/p/6089030.html
Copyright © 2011-2022 走看看