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
  • 相关阅读:
    思念
    空白
    curl json string with variable All In One
    virtual scroll list All In One
    corejs & RegExp error All In One
    socket.io All In One
    vue camelCase vs PascalCase vs kebabcase All In One
    element ui 表单校验,非必填字段校验 All In One
    github 定时任务 UTC 时间不准确 bug All In One
    input range & color picker All In One
  • 原文地址:https://www.cnblogs.com/accumulater/p/6089030.html
Copyright © 2011-2022 走看看