示例#1
0
        public BaseCaptcha GenerateBitmapCaptcha(int height = 30, int width = 100, RectangleCaptcha rectf = null)
        {
            string generatedValue = GenerateStringCaptcha();
            Stream stream         = GenerateStreamCaptcha(generatedValue, height, width, rectf);

            return(new StreamCaptcha()
            {
                GeneratedValue = generatedValue,
                Stream = stream
            });
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public BaseCaptcha GenerateCaptcha(int height = 30, int width = 100, RectangleCaptcha rectf = null)
        {
            string generatedValue = GenerateStringCaptcha();

            byte[] byteArr = GenerateStreamCaptcha(generatedValue, height, width, rectf).ToArray();
            string binStr  = Convert.ToBase64String(byteArr);

            return(new Base64Captcha()
            {
                GeneratedValue = generatedValue,
                GeneratedImageBase64 = binStr
            });
        }
示例#3
0
        public Bitmap GenerateBitmapCaptcha(string stringCaptcha, int height = 30, int width = 100, RectangleCaptcha rectf = null)
        {
            Bitmap   bmp = new Bitmap(width, height);
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(Color.White);
            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            g.DrawString(stringCaptcha, new Font("Thaoma", 15, FontStyle.Strikeout), Brushes.Green, RectangleCaptcha.ToRectangleF(rectf));
            g.DrawRectangle(new Pen(Brushes.LemonChiffon), 1, 1, width - 8, height - 2);
            g.Flush();
            g.Dispose();
            return(bmp);
        }
示例#4
0
        public MemoryStream GenerateStreamCaptcha(string stringCaptcha, int height = 30, int width = 100, RectangleCaptcha rectf = null)
        {
            Bitmap       bmp          = GenerateBitmapCaptcha(stringCaptcha, height, width, rectf);
            MemoryStream memoryStream = new MemoryStream();

            bmp.Save(memoryStream, ImageFormat.Jpeg);
            bmp.Dispose();
            memoryStream.Dispose();
            return(memoryStream);
        }