コード例 #1
0
        /// <summary>
        /// 图片验证码
        /// </summary>
        public ActionResult Validate()
        {
            Bitmap     bmp  = new Bitmap(80, 40);
            Graphics   g    = Graphics.FromImage(bmp);
            SolidBrush sb   = new SolidBrush(ValidateCodeHelper.GetColor());
            var        code = ValidateCodeHelper.BuildCode(4);

            CookieHelper.SetCookie("Validate", code, DateTime.Now.AddMinutes(5));
            g.DrawString(code, new Font("宋体", 20), sb, 0, 0);
            MemoryStream ms = new MemoryStream();

            bmp.Save(ms, ImageFormat.Png);
            return(File(ms.GetBuffer(), "application/x-png"));
        }