コード例 #1
0
        public static NCaptcha GenerateAndDraw(byte showCount, System.IO.Stream outStream, EnImage enImg, string SetSessionName)
        {
            NCaptcha code = new NCaptcha(showCount);

            code.SetSessionName = SetSessionName;
            code.IsSetSession   = true;

            EnFont font = new EnFont();

            font.MyFont  = enImg.ImgFont;
            font.MyColor = enImg.ImgColor;
            EnImage img = new EnImage();

            img.ImgColor = Color.White;
            ;
            img.Width  = enImg.Width;
            img.Height = enImg.Height;

            code.gBitmap = code.gDrawing(EnImage.PaintShape.Link, img, font);
            if (code.gBitmap != null && outStream != null)
            {
                code.gBitmap.Save(outStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            return(code);
        }
コード例 #2
0
        /// <summary>
        /// 生成随机字符串并生成图片
        /// </summary>
        /// <param name="showCount">字符串长度</param>
        /// <param name="outStream">输出流,可以为NULL</param>
        /// <param name="iformat">图片类型</param>
        /// <param name="isSetSession">是否保存Session中</param>
        /// <returns>返回对象</returns>
        public static NCaptcha GenerateAndDraw(byte showCount, System.IO.Stream outStream, System.Drawing.Imaging.ImageFormat iformat, bool isSetSession)
        {
            NCaptcha code = new NCaptcha(showCount);

            code.IsSetSession = isSetSession;

            EnFont font = new EnFont();

            font.MyFont  = new Font(FontFamily.GenericSerif, 20, FontStyle.Bold, GraphicsUnit.Point);
            font.MyColor = EnObject.listColor[0];
            EnImage img = new EnImage();

            img.ImgColor = Color.White;
            ;
            img.Width  = code.GenerateCount * (int)font.MyFont.Size;
            img.Height = (int)(font.MyFont.Size) + 5;

            code.gBitmap = code.gDrawing(EnImage.PaintShape.Link, img, font);
            if (code.gBitmap != null && outStream != null)
            {
                code.gBitmap.Save(outStream, iformat);
            }
            return(code);
        }