Ejemplo n.º 1
0
        private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Pen p)
        {
            BorderStyleEnum ls = getLineStyle(p);

            switch (p.Brush.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)p.Brush;
                PageRectangle pl = new PageRectangle();
                pl.X = X + recX * SCALEFACTOR;
                pl.Y = Y + recY * SCALEFACTOR;
                pl.W = recWidth * SCALEFACTOR;
                pl.H = recHeight * SCALEFACTOR;

                StyleInfo SI = new StyleInfo();
                SI.Color     = theBrush.Color;
                SI.BColorTop = SI.BColorBottom = SI.BColorLeft = SI.BColorRight = theBrush.Color;
                SI.BStyleTop = SI.BStyleBottom = SI.BStyleLeft = SI.BStyleRight = ls;
                SI.BWidthTop = SI.BWidthBottom = SI.BWidthLeft = SI.BWidthRight = p.Width * SCALEFACTOR;
                pl.SI        = SI;
                items.Add(pl);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        private void DoInstructions(Single Xp, Single Yp, Single Wid, Single Hgt, Brush b)
        {
            switch (b.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)b;
                Color       col = theBrush.Color;
                PageEllipse pl  = new PageEllipse();
                pl.X = X + Xp * SCALEFACTOR;
                pl.Y = Y + Yp * SCALEFACTOR;
                pl.W = Wid * SCALEFACTOR;
                pl.H = Hgt * SCALEFACTOR;

                StyleInfo SI = new StyleInfo();
                SI.BackgroundColor = col;
                pl.SI = SI;
                items.Add(pl);



                //Lines.AppendFormat("\r\n"); //CrLf
                //Lines.AppendFormat("q\t"); //Push graphics state onto stack
                //Lines.AppendFormat("{0} w\t", 1 * ScaleX); //set width of path
                //Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
                //Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
                ////Need some bezier curves to  draw an ellipse.. we can't draw a circle, but we can get close.
                //Double k = 0.5522847498;
                //Double RadiusX = (Wid / 2.0) * ScaleX;
                //Double RadiusY = (Hgt / 2.0) * ScaleY;
                //Double Y4 = Y + Height - Yp * ScaleY;
                //Double X1 = Xp * ScaleX + X;
                //Double Y1 = Y4 - RadiusY;
                //Double X4 = X1 + RadiusX;
                //Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..
                //Double kRy = k * RadiusY;
                //Double kRx = k * RadiusX;
                ////Control Point 1 will be on the same X as point 1 and be -kRy Y
                //Double X2 = X1;
                //Double Y2 = Y1 + kRy;
                //Double X3 = X4 - kRx;
                //Double Y3 = Y4;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant
                //X1 += 2 * RadiusX;
                //X2 = X1;
                //X3 += 2 * kRx;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant
                //Y2 -= 2 * kRy;
                //Y3 -= 2 * RadiusY;
                //Y4 = Y3;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant
                //X1 -= 2 * RadiusX;
                //X2 = X1;
                //X3 -= 2 * kRx;
                //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant
                //Lines.AppendFormat("f\t");//fill path
                //Lines.AppendFormat("Q\t");//Pop graphics state from stack
                break;
            }
        }
Ejemplo n.º 3
0
        private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Brush b, Single StartAngle, Single SweepAngle)
        {
            PagePie pl = new PagePie();

            pl.StartAngle = StartAngle;
            pl.SweepAngle = SweepAngle;

            StyleInfo SI = new StyleInfo();

            pl.X = X + recX * SCALEFACTOR;
            pl.Y = Y + recY * SCALEFACTOR;
            pl.W = recWidth * SCALEFACTOR;
            pl.H = recHeight * SCALEFACTOR;

            switch (b.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)b;
                SI.Color           = theBrush.Color;
                SI.BackgroundColor = theBrush.Color;
                break;

            case "LinearGradientBrush":
                System.DrawingCore.Drawing2D.LinearGradientBrush linBrush = (System.DrawingCore.Drawing2D.LinearGradientBrush)b;
                SI.BackgroundGradientType     = BackgroundGradientTypeEnum.LeftRight;
                SI.BackgroundColor            = linBrush.LinearColors[0];
                SI.BackgroundGradientEndColor = linBrush.LinearColors[1];
                break;

            case "HatchBrush":
                System.DrawingCore.Drawing2D.HatchBrush hatBrush = (System.DrawingCore.Drawing2D.HatchBrush)b;
                SI.BackgroundColor = hatBrush.BackgroundColor;
                SI.Color           = hatBrush.ForegroundColor;

                SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle);
                break;

            default:
                break;
            }

            pl.SI = SI;
            items.Add(pl);
        }
Ejemplo n.º 4
0
        private void DoInstructions(PointF[] points, Pen p, UInt32 Offset, UInt32 NumberOfPoints, float Tension)
        {
            BorderStyleEnum ls = getLineStyle(p);

            //Well we only draw lines at the moment....

            switch (p.Brush.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)p.Brush;
                PageCurve pc = new PageCurve();
                for (int i = 0; i < points.Length; i++)
                {
                    points[i].X = X + points[i].X * SCALEFACTOR;
                    points[i].Y = Y + points[i].Y * SCALEFACTOR;
                }
                pc.Points  = points;
                pc.Offset  = (int)Offset;
                pc.Tension = Tension;


                StyleInfo SI = new StyleInfo();
                SI.Color        = theBrush.Color;
                SI.BColorTop    = theBrush.Color;
                SI.BStyleTop    = ls;
                SI.BWidthTop    = p.Width * SCALEFACTOR;
                SI.BColorBottom = theBrush.Color;
                SI.BStyleBottom = ls;
                SI.BWidthBottom = p.Width * SCALEFACTOR;
                SI.BColorLeft   = theBrush.Color;
                SI.BStyleLeft   = ls;
                SI.BWidthLeft   = p.Width * SCALEFACTOR;
                SI.BColorRight  = theBrush.Color;
                SI.BStyleRight  = ls;
                SI.BWidthRight  = p.Width * SCALEFACTOR;
                pc.SI           = SI;
                items.Add(pc);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 5
0
        private void DoInstructions(PointF[] Ps, Brush b)
        {
            PagePolygon pl = new PagePolygon();

            //pl.X = X * SCALEFACTOR;
            //pl.Y = Y * SCALEFACTOR;
            pl.Points = Ps;
            StyleInfo SI = new StyleInfo();

            switch (b.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)b;
                SI.Color           = theBrush.Color;
                SI.BackgroundColor = theBrush.Color;
                break;

            case "LinearGradientBrush":
                System.DrawingCore.Drawing2D.LinearGradientBrush linBrush = (System.DrawingCore.Drawing2D.LinearGradientBrush)b;
                SI.BackgroundGradientType     = BackgroundGradientTypeEnum.LeftRight;
                SI.BackgroundColor            = linBrush.LinearColors[0];
                SI.BackgroundGradientEndColor = linBrush.LinearColors[1];
                break;

            case "HatchBrush":
                System.DrawingCore.Drawing2D.HatchBrush hatBrush = (System.DrawingCore.Drawing2D.HatchBrush)b;
                SI.BackgroundColor = hatBrush.BackgroundColor;
                SI.Color           = hatBrush.ForegroundColor;
                SI.PatternType     = StyleInfo.GetPatternType(hatBrush.HatchStyle);
                break;

            default:
                break;
            }

            pl.SI = SI;
            items.Add(pl);
        }
Ejemplo n.º 6
0
        private void DoInstructions(Single Xa, Single Xb, Single Ya, Single Yb, Pen p)
        {
            BorderStyleEnum ls = getLineStyle(p);


            switch (p.Brush.GetType().Name)
            {
            case "SolidBrush":
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)p.Brush;
                PageLine pl = new PageLine();
                pl.X  = X + Xa * SCALEFACTOR;
                pl.Y  = Y + Ya * SCALEFACTOR;
                pl.X2 = X + Xb * SCALEFACTOR;
                pl.Y2 = Y + Yb * SCALEFACTOR;

                StyleInfo SI = new StyleInfo();
                SI.Color        = theBrush.Color;
                SI.BColorTop    = theBrush.Color;
                SI.BStyleTop    = ls;
                SI.BWidthTop    = p.Width * SCALEFACTOR;
                SI.BColorBottom = theBrush.Color;
                SI.BStyleBottom = ls;
                SI.BWidthBottom = p.Width * SCALEFACTOR;
                SI.BColorLeft   = theBrush.Color;
                SI.BStyleLeft   = ls;
                SI.BWidthLeft   = p.Width * SCALEFACTOR;
                SI.BColorRight  = theBrush.Color;
                SI.BStyleRight  = ls;
                SI.BWidthRight  = p.Width * SCALEFACTOR;
                pl.SI           = SI;
                items.Add(pl);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="checkCode"></param>
        /// <returns></returns>
        public static MemoryStream GenerateCheckCode(out string checkCode)
        {
            checkCode = string.Empty;
            //颜色列表,用于验证码、噪线、噪点
            Color color = ColorTranslator.FromHtml("#1AE61A");

            //验证码的字符集,去掉了一些容易混淆的字符
            char[] character = { '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' };
            Random rnd       = new Random();

            //生成验证码字符串
            for (int i = 0; i < 4; i++)
            {
                checkCode += character[rnd.Next(character.Length)];
            }

            int      iwidth = 130;
            Bitmap   image  = new Bitmap(iwidth, 38);
            Graphics g      = Graphics.FromImage(image);
            Random   random = new Random(System.DateTime.Now.Millisecond);

            Brush b = new System.DrawingCore.SolidBrush(Color.FromArgb(4683611));

            g.Clear(ColorTranslator.FromHtml("#EBFDDF"));
            using (StringFormat format = new StringFormat())
            {
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.FormatFlags   = StringFormatFlags.NoWrap;
                Matrix matrix = new Matrix();
                float  offsetx = -25, offsety = 0;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                for (int i = 0; i < checkCode.Length; i++)
                {
                    int   fsize = random.Next(20, 24);
                    Font  f     = CreateFont(IOHelper.GetMapPath("/Fonts/CheckCode.ttf"), fsize, FontStyle.Bold, GraphicsUnit.Point, 0);
                    SizeF size  = g.MeasureString(checkCode[i].ToString(), f);
                    matrix.RotateAt(random.Next(-15, 10), new PointF(offsetx + size.Width / 2, offsety + size.Height / 2));
                    g.Transform = matrix;

                    g.DrawString(
                        checkCode[i].ToString(),
                        f,
                        Brushes.Green,
                        new RectangleF(
                            offsetx,
                            offsety,
                            image.Width,
                            image.Height),
                        format);
                    //g.DrawString(checkCode, f, b, 3, 3);
                    offsetx += size.Width * 3 / 5;
                    offsety += -0;
                    g.RotateTransform(0);
                    matrix.Reset();
                    f.Dispose();
                }
            }


            Pen blackPen = new Pen(Color.Black, 0);
            //将验证码图片写入内存流,并将其以 "image/Png" 格式输出
            MemoryStream ms = new MemoryStream();

            try
            {
                image.Save(ms, ImageFormat.Png);
                return(ms);
            }
            finally
            {
                //显式释放资源
                image.Dispose();
                g.Dispose();
            }
        }
Ejemplo n.º 8
0
        private void DoEllipse(Pen p, Single Xp, Single Yp, Single Wid, Single Hgt)
        {
            BorderStyleEnum ls = getLineStyle(p);

            Color col = Color.Black;

            if (p.Brush.GetType().Name.Equals("SolidBrush"))
            {
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)p.Brush;
                col = theBrush.Color;
            }

            PageEllipse pl = new PageEllipse();

            pl.X = X + Xp * SCALEFACTOR;
            pl.Y = Y + Yp * SCALEFACTOR;
            pl.W = Wid * SCALEFACTOR;
            pl.H = Hgt * SCALEFACTOR;

            StyleInfo SI = new StyleInfo();

            SI.Color     = col;
            SI.BColorTop = col;
            SI.BStyleTop = ls;
            SI.BWidthTop = p.Width * SCALEFACTOR;
            pl.SI        = SI;
            items.Add(pl);

            //Lines.AppendFormat("\r\n"); //CrLf
            //Lines.AppendFormat("q\t"); //Push graphics state onto stack
            //Lines.AppendFormat("{0} w\t", p.Width * ScaleX); //set width of path
            //Lines.AppendFormat("{0} \t", linestyle); //line style from pen...
            //Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            //Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            ////Need some bezier curves to  draw an ellipse.. we can't draw a circle, but we can get close.
            //Double k = 0.5522847498;
            //Double RadiusX = (Wid / 2.0) * ScaleX;
            //Double RadiusY = (Hgt / 2.0) * ScaleY;
            //Double Y4 = Y + Height - Yp * ScaleY;
            //Double X1 = Xp * ScaleX + X;
            //Double Y1 = Y4 - RadiusY;
            //Double X4 = X1 + RadiusX;

            //Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..

            //Double kRy = k * RadiusY;
            //Double kRx = k * RadiusX;

            ////Control Point 1 will be on the same X as point 1 and be -kRy Y
            //Double X2 = X1;
            //Double Y2 = Y1 + kRy;

            //Double X3 = X4 - kRx;
            //Double Y3 = Y4;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant

            //X1 += 2 * RadiusX;
            //X2 = X1;
            //X3 += 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant

            //Y2 -= 2 * kRy;
            //Y3 -= 2 * RadiusY;
            //Y4 = Y3;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant

            //X1 -= 2 * RadiusX;
            //X2 = X1;
            //X3 -= 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant

            //Lines.AppendFormat("S\t");//Stroke path
            //Lines.AppendFormat("Q\t");//Pop graphics state from stack
        }
        /// <summary>
        /// 创建验证码的图片
        /// </summary>
        /// <param name="validateCode">验证码</param>
        /// <param name="height">图片高度</param>
        /// <param name="rightOffsetWidth">文字的右边偏移量宽度</param>
        /// <returns></returns>
        public static byte[] CreateValidateGraphic(string validateCode, int height, int leftOffsetWidth, int rightOffsetWidth)
        {
            int      randAngle = 45;                           //随机转动角度
            int      mapwidth  = (int)(validateCode.Length * 24) + leftOffsetWidth + rightOffsetWidth;
            Bitmap   image     = new Bitmap(mapwidth, height); //创建图片背景
            Graphics graph     = Graphics.FromImage(image);

            try
            {
                graph.Clear(Color.AliceBlue);//清除画面,填充背景
                Random rand = new Random();



                //验证码旋转,防止机器识别
                char[] chars = validateCode.ToCharArray();//拆散字符串成单字符数组

                //文字距中
                StringFormat format = new StringFormat(StringFormatFlags.NoClip);
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                //定义颜色
                Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
                //定义字体
                string[] font   = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };
                int      cindex = rand.Next(7);

                for (int i = 0; i < chars.Length; i++)
                {
                    int findex = rand.Next(5);

                    Font  f = new System.DrawingCore.Font(font[findex], 20, System.DrawingCore.FontStyle.Bold);//字体样式(参数2为字体大小)
                    Brush b = new System.DrawingCore.SolidBrush(c[cindex]);

                    Point dot = new Point(20, 12);
                    //graph.DrawString(dot.X.ToString(),fontstyle,new SolidBrush(Color.Black),10,150);//测试X坐标显示间距的
                    float angle = rand.Next(-randAngle, randAngle); //转动的度数

                    graph.TranslateTransform(dot.X, dot.Y);         //移动光标到指定位置
                    graph.RotateTransform(angle);
                    graph.DrawString(chars[i].ToString(), f, b, 0, 5, format);
                    //graph.DrawString(chars[i].ToString(),fontstyle,new SolidBrush(Color.Blue),1,1,format);
                    graph.RotateTransform(-angle);        //转回去
                    graph.TranslateTransform(-2, -dot.Y); //移动光标到指定位置,每个字符紧凑显示,避免被软件识别
                }
                Brush lb = new System.DrawingCore.SolidBrush(c[cindex]);
                graph.TranslateTransform(-graph.Transform.OffsetX, -graph.Transform.OffsetY);
                // graph.DrawLine(new Pen(Color.DarkGray, 3), 0, image.Height / 2, image.Width, image.Height / 2);
                int x1 = 0;
                int x2 = 0;
                int y1 = 0;
                int y2 = 0;
                int lt = image.Width / 20;
                int dy = 2;
                //背景噪点生成
                for (int i = 0; i < 30; i++)
                {
                    x1 = i == 0 ? lt * i : x2;
                    y1 = i == 0 ? (image.Height / 2 + rand.Next(-dy, dy)) : y2;
                    x2 = x1 + lt;
                    y2 = image.Height / 2 + rand.Next(-dy, dy);
                    graph.DrawLine(new Pen(Color.DarkGray, 2), x1, y1, x2, y2);
                }

                //for (int i = 0; i < 0; i++)
                //{

                //    int x11 = rand.Next(image.Width);
                //    int x12 = rand.Next(image.Width);
                //    int y11 = rand.Next(image.Height);
                //    int y12 = rand.Next(image.Height);
                //    graph.DrawLine(new Pen(Color.DarkGray), x11, y11, x12, y12);
                //}

                //生成图片
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    image.Save(ms, System.DrawingCore.Imaging.ImageFormat.Gif);
                    return(ms.ToArray());
                }
            }
            finally
            {
                graph.Dispose();
                image.Dispose();
            }
        }