Example #1
0
        public static MemoryStream GenerateImage(string code)
        {
            var imageStream = ImageFactory.GenerateImage(code);

            imageStream.Position = 0;
            return(imageStream);
        }
Example #2
0
        public ActionResult CreateVerifyCode()
        {
            //产生4位验证码
            string verifyCode = CommonHelper.CreateVerifyCode(4);

            //验证码放入Session
            //Session["verifyCode"] = verifyCode;
            //验证码应该放入TempData
            TempData["verifyCode"] = verifyCode;
            #region

            /*
             * using (MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6))
             * //用组件生成验证码图片
             * //using (FileStream fs = File.OpenWrite(@"c:\temp\1.jpg"))
             * {   //不保存到文件里了
             *  //FileStreamResult
             *  return File(ms, "image/jpeg");
             *  //返回服务器一个图片流
             *
             * }
             */
            #endregion
            //EF会自己dispose
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);
            return(File(ms, "image/jpeg"));
        }
Example #3
0
        /// <summary>
        /// Returns a response message as an image.
        /// </summary>
        /// <param name="id">Captcha string for which the image is to be generated</param>
        /// <returns>HttpResponseMessage with "image/jpeg" header</returns>
        public IActionResult Get(string id)
        {
            var imageStream = ImageFactory.GenerateImage(id);

            imageStream.Position = 0;
            return(File(imageStream, "image/jpeg"));
        }
Example #4
0
 /// <summary>
 /// 生成验证码图片
 /// </summary>
 /// <param name="fileName"></param>
 public static void BuildCaptchaPicture(string code, string fileName)
 {
     using (MemoryStream ms = ImageFactory.GenerateImage(code, 60, 100, 20, 6))
         using (FileStream fs = File.OpenWrite(fileName))
         {
             ms.CopyTo(fs);
         }
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 public void CreateValidateImage(string msg, int height = 60, int width = 150, int size = 30, int n = 10)
 {
     using (MemoryStream ms = ImageFactory.GenerateImage(msg, height, width, size, n))
         using (FileStream fs = File.OpenWrite(@"d:\1.jpg"))
         {
             ms.CopyTo(fs);
         }
 }
Example #6
0
        public ActionResult CreateVerifyCode()
        {
            var          verifyCode = CommonHelper.GenerateCaptchaCode(4);
            MemoryStream picStream  = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);

            TempData["verifyCode"] = verifyCode;
            return(File(picStream, "image/jpeg"));
        }
Example #7
0
 public static void GenerateCaptchaCodeImage()
 {
     using (MemoryStream ms = ImageFactory.GenerateImage("AB12", 60, 100, 20, 6))
         using (FileStream fs = File.OpenWrite(@"C:\Program Files\longCode\LongRoom\Long.Test\img\1.jpg"))
         {
             ms.CopyTo(fs);
         }
 }
Example #8
0
        public ActionResult CreateCaptcha()
        {
            string code = CommonHelper.CreateVerifyCode(4);
            //MemoryStream ms = ImageFactory.GenerateImage(code, 35, 100, 9, 6);
            MemoryStream ms = ImageFactory.GenerateImage(code, 60, 150, 20, 6);

            TempData["code"] = code;
            return(File(ms, "image/jpeg"));
        }
Example #9
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.GetCaptcha(4);

            TempData["verifyCode"] = verifyCode;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }
Example #10
0
        /// <summary>
        /// 获取图片验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetVerifyCode()
        {
            string verifyCode = WebCommonHelper.CreateVerifyCode(5);

            TempData["verifyCodeFront"] = verifyCode;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 51, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }
Example #11
0
        public ActionResult Code()
        {
            string code = CommonHelper.CreateVerifyCode(4);

            TempData["code"] = code;
            MemoryStream memory = ImageFactory.GenerateImage(code, 55, 100, 20, 6);

            return(File(memory, "image/jpeg"));
        }
Example #12
0
        //这个方法是跟Main中的创建验证码是一样的,但是我认为register下面的方法就写在这个下面,或者提到公共方法里面给全部程序调用。
        public ActionResult CreateVerifyCode()
        {
            string verifycode = commonhelper.CreateVerifyCode(4);

            //每调用一次这个方法都会更新一次这个controller里面的VerifyCode属性。
            VerifyCode = verifycode;
            MemoryStream ms = ImageFactory.GenerateImage(verifycode, 50, 70, 20, 0);

            return(File(ms, "image/jpeg"));
        }
Example #13
0
 //生成图片验证码
 //安装 CaptchaGen
 static void ImageFactorys()
 {
     using (MemoryStream ms =
                ImageFactory.GenerateImage("a123fdasfa32", 80, 150,
                                           30, 10))
         using (FileStream fs = File.OpenWrite(@"E:\Program\NET高级培训\NET掌上租\TEST\Image\4.jpg"))
         {
             ms.CopyTo(fs);
         }
 }
Example #14
0
        public void GenerateImageTest()
        {
            string testString = "fEwS21";
            var    stream     = ImageFactory.GenerateImage(testString);

            Assert.IsNotNull(stream);
            Bitmap image = Image.FromStream(stream) as Bitmap;

            Assert.AreEqual(image.Width, 150);
        }
Example #15
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.CreateVerifyCode(4);

            //验证码保存到TempData中最安全
            TempData["verifyCode"] = verifyCode;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 15, 6);

            return(File(ms, "image/jpeg"));
        }
Example #16
0
 /// <summary>
 /// 生成验证码图片
 /// install CaptchaGen
 /// 扩展 GEETEST 拖动验证码
 /// </summary>
 /// <param name="code">验证码</param>
 /// <param name="height">高度</param>
 /// <param name="width">宽度</param>
 /// <param name="fontSize">字体大小</param>
 /// <param name="distortion">扭曲程度</param>
 /// <param name="savePath">保存路径</param>
 /// <param name="newName">图片名字</param>
 public static void GetCodeImage(string code, int height, int width, int fontSize, int distortion, string savePath, string newName)
 {
     using (MemoryStream ms = ImageFactory.GenerateImage(code, height, width, fontSize, distortion))
     {
         using (FileStream fs = File.OpenWrite(savePath + @"\" + newName + ".jpg"))
         {
             ms.CopyTo(fs);
         }
     }
 }
Example #17
0
        public void GenerateImageTest()
        {
            string testString = "fEwS21";
            var    stream     = ImageFactory.GenerateImage(testString);

            stream.ShouldNotBeNull();
            Bitmap image = Image.FromStream(stream) as Bitmap;

            image.Width.ShouldBe(150);
        }
Example #18
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.GetCaptcha(4);

            TempData["verifyCode"]       = verifyCode;
            ImageFactory.BackgroundColor = Color.YellowGreen;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 55, 85, 20, 0);

            byte[] bytes = CommonHelper.CaptureImage(ms, 5, 17, 80, 38);
            return(File(bytes, "image/jpeg"));
        }
Example #19
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetVarCode()
        {
            //利用CaptchaGen验证码组件,用法参照文档,先通过Nuget安装组件 Install-PackAge CaptchaGen
            //1:获取验证码文字
            var VerNum = CommonHelper.CreateVerifyCode(4);

            TempData["code"] = VerNum;                                             //保存到Sesion里面,使用过一次后就自动清除,这就是TempData的用法
            MemoryStream ms = ImageFactory.GenerateImage(VerNum, 40, 100, 12, -1); //此处不能用using语法 验证码文字 高度;宽度; 字体大小;扭曲程度,数值越大扭曲越厉害

            return(File(ms, "image/jpeg"));
        }
Example #20
0
        public ActionResult GetVerCode()
        {
            //利用CaptchaGen验证码组件,用法参照文档,先通过Nuget安装组件 Install-PackAge CaptchaGen
            //1:获取验证码文字
            var VerNum = ToolsCommon.CreateVerifyCode(4);

            TempData["code"] = VerNum;                                            //保存到Sesion里面,使用过一次后就自动清除,这就是TempData的用法
            MemoryStream ms = ImageFactory.GenerateImage(VerNum, 60, 100, 20, 6); //此处不能用using语法

            return(File(ms, "image/jpeg"));
        }
Example #21
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.GetCaptcha(4);

            TempData["AdminVerifyCode"]  = verifyCode;
            ImageFactory.BackgroundColor = Color.White;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 55, 78, 18, 0);

            byte[] bytes = CommonHelper.CaptureImage(ms, 10, 17, 65, 38);
            return(File(bytes, "image/jpeg"));
        }
Example #22
0
        public ActionResult CreatVerifyCode()
        {
            string verifyCode = CommonHelper.CreateVerifyCode(4);

            //Session["verifyCode"] = verifyCode;
            //使用TempData,用完删除
            TempData["verifyCode"] = verifyCode;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }
Example #23
0
        public ActionResult CreateVerifyCode()
        {
            var verifyCode = CommonHelper.GenerateCaptchaCode(4);

            TempData["verifyCode"] = verifyCode;                                      //放在tempdata中取一次就自动销毁
            //TODO:有网了把验证码插件装上
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 50, 100, 20, 6); //高度,宽度,字体大小,扭曲程度

            return(File(ms, "image/jpeg"));
            //暂时这样给回去自己看
            //return Json(new AjaxResult(){Status = verifyCode});
        }
Example #24
0
        public ActionResult CreateVerifyCode()
        {
            var verifyCode = Common.CommonHelper.CreateVerifyCode(4);

            TempData["verifycode"] = verifyCode;

            //Session["verifycode"] = verifyCode;

            var ms = ImageFactory.GenerateImage(verifyCode, 45, 100, 20);

            return(File(ms, "image/jpeg"));
        }
Example #25
0
        public void GenerateImageWithImageAttributesTest()
        {
            string testString = "fEwS21";
            int    height = 135, width = 250;
            var    stream = ImageFactory.GenerateImage(testString, height, width, 23);

            stream.ShouldNotBeNull();
            Bitmap image = Image.FromStream(stream) as Bitmap;

            image.Width.ShouldBe(width);
            image.Height.ShouldBe(height);
        }
Example #26
0
        public void GenerateImageWithImageAttributesTest()
        {
            string testString = "fEwS21";
            int    height = 135, width = 250;
            var    stream = ImageFactory.GenerateImage(testString, height, width, 23);

            Assert.IsNotNull(stream);
            Bitmap image = Image.FromStream(stream) as Bitmap;

            Assert.AreEqual(image.Width, width);
            Assert.AreEqual(image.Height, height);
        }
Example #27
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.GenerateCaptchaCode(4);

            // Session["verifyCode"] = verifyCode;//验证码保存在Session中,不安全,容易被暴力破解,浏览器上的东西是不可信的
            TempData["verifyCode"] = verifyCode;
            //using (MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6))
            //{
            //    return File(ms,"image/jpeg");
            //}
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }
Example #28
0
        public ActionResult CreateVerifyCode()
        {
            string verifycode = commonhelper.CreateVerifyCode(4);

            TempData["verifyCode"] = verifycode;

            /* using (MemoryStream ms=ImageFactory.GenerateImage(verifycode,60,100,20,60))
             * {
             *   return File(ms, "image/jpeg");
             * }*/
            MemoryStream ms = ImageFactory.GenerateImage(verifycode, 50, 70, 20, 0);

            return(File(ms, "image/jpeg"));
        }
Example #29
0
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.CreateVerifyCode(4);

            Session["verifyCode"]  = verifyCode;
            TempData["verifyCode"] = verifyCode;
            //Session["verifyCode"] = verifyCode;

            /*
             * using (MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6))
             * {
             *  return File(ms, "image/jpeg");
             * }*/
            System.IO.MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);
            return(File(ms, "image/jpeg"));
        }
        public ActionResult CreateVerifyCode()
        {
            string verifyCode = CommonHelper.CreateVerifyCode(4);

            TempData["verifyCodeHome"] = verifyCode;
            //Session["verifyCode"] = verifyCode;

            /*
             * using (MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6))
             * {
             *  return File(ms, "image/jpeg");
             * }*/
            ImageFactory.BackgroundColor = Color.AliceBlue;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 60, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }