码迷,mamicode.com
首页 > 其他好文 > 详细

生成验证码

时间:2014-05-08 23:22:43      阅读:398      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   ext   

bubuko.com,布布扣
private byte[] GetValidateCodeImage()
        {
            string VNum = RndNum(4);
            Bitmap Img = new Bitmap(VNum.Length * 16, 25);
            Graphics g = Graphics.FromImage(Img);
            g.DrawString(VNum, (new Font("Verdana", 10)), (new SolidBrush(Color.FromArgb(85,85,85))), 3, 3);
            MemoryStream ms = new MemoryStream();
            Img.Save(ms, ImageFormat.Png);
            g.Dispose();
            Img.Dispose();
            Session["LocalAuthCode"] = VNum;
            return ms.ToArray();
        }

        private string RndNum(int VcodeNum)
        {
            string str = @"0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
            string VNum = "";
            Random rnd = new Random();
            for (int i = 0; i < VcodeNum; i++)
            {
                VNum = VNum + str.Substring(0 + rnd.Next(61), 1);
            }
            return VNum;
        }
bubuko.com,布布扣

 

生成验证码,布布扣,bubuko.com

生成验证码

标签:style   blog   class   code   java   ext   

原文地址:http://www.cnblogs.com/rebecca-ty/p/3716687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!