public string Genrate()
        {
            //System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            //CaptchaImage img = new CaptchaImage(150, 50, family);
            //string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
            //_session["Captcha"] = text;
            //img.SetText(text);
            //img.GenerateImage();
            //MemoryStream ms = new MemoryStream();
            //img.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            //HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            //result.Content = new ByteArrayContent(ms.ToArray());
            //result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
            //return result;

            var family = new System.Drawing.FontFamily("Arial");
            var img    = new CaptchaImage(150, 50, family);
            //string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
            var text = img.CreateRandomText(4);

            _session.Store("Captcha", text);
            img.SetText(text);
            img.GenerateImage();
            var ms = new MemoryStream();

            img.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return(Convert.ToBase64String(ms.ToArray()));
        }
        public ActionResult generateCaptcha()
        {
            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img  = new CaptchaImage(150, 50, family);
            string       text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);

            img.SetText(text);
            img.GenerateImage();
            img.Image.Save(Server.MapPath("~") + this.Session.SessionID.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
            Session["captchaText"] = text;
            return(Json(this.Session.SessionID.ToString() + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public ActionResult GenerateCaptcha()
        {
            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img  = new CaptchaImage(150, 50, family);
            string       text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);

            img.SetText(text);
            img.GenerateImage();
            img.Image.Save(Server.MapPath("~") +
                           "\\" +
                           ConfigurationManager.AppSettings["CaptchaFolder"] + "\\" +
                           this.Session.SessionID.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
            Session["Captcha"] = new CaptchaViewModel
            {
                CaptchaText = text
            };
            return(Json(this.Session.SessionID.ToString() + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult generateCaptcha()
        {
            var    dropdowndata = this.Session.SessionID.ToString() + ".png";
            string filePath     = AppDomain.CurrentDomain.BaseDirectory + "./Content/writereaddata/Captcha/" + dropdowndata;

            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img  = new CaptchaImage(150, 50, family);
            string       text = img.CreateRandomText(4).ToUpper();

            img.SetText(text);
            img.GenerateImage();
            Session["captchaText"] = text;
            img.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
            byte[] d = System.IO.File.ReadAllBytes(filePath);
            System.IO.File.Delete(filePath);
            //return File(d, "application/octet-stream");
            var bytestrim = d;

            return(base.File(bytestrim, "image/png"));
            //return Json("/Content/writereaddata/Captcha/" + dropdowndata + "?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet);
            //test
        }
Пример #5
0
        public ActionResult generateCaptcha()
        {
            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img  = new CaptchaImage(88, 36, family);
            string       text = img.CreateRandomText(5);

            img.SetText(text);
            img.GenerateImage();
            var imgName = Guid.NewGuid().ToString();

            img.Image.Save(Server.MapPath("/Content/captcha/") + imgName + ".png", System.Drawing.Imaging.ImageFormat.Png);
            Session["captchaText"] = text;
            var catModel = new
            {
                src = "/Content/captcha/" + imgName + ".png?t=" + DateTime.Now.Ticks
                      //capt = text
            };

            return(new JsonResult()
            {
                Data = catModel, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }