Example #1
0
        public override IPen ToPen(float scale)
        {
            float width = scale * Width;
            IPen  pen   = null;

            switch (DashStyle)
            {
            case DashStyle.Solid:
                pen = Pens.Solid(Color, width);
                break;

            case DashStyle.Dash:
                pen = Pens.Dash(Color, width);
                break;

            case DashStyle.Dot:
                pen = Pens.Dot(Color, width);
                break;

            case DashStyle.DashDot:
                pen = Pens.DashDot(Color, width);
                break;

            case DashStyle.DashDotDot:
                pen = Pens.DashDotDot(Color, width);
                break;
            }
            return(pen);
        }
Example #2
0
        public void DrawLines_Dot <TPixel>(TestImageProvider <TPixel> provider, string colorName, float alpha, float thickness, bool antialias)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha);
            Pen   pen   = Pens.Dot(color, thickness);

            DrawLinesImpl(provider, colorName, alpha, thickness, antialias, pen);
        }
Example #3
0
        public void ImageShouldBeOverlayedByPathDotted()
        {
            string path = TestEnvironment.CreateOutputDirectory("Drawing", "Lines");

            using (var image = new Image <Rgba32>(500, 500))
            {
                image.Mutate(x => x.BackgroundColor(Rgba32.Blue));
                image.Mutate(x => x.DrawLines(Pens.Dot(Rgba32.HotPink, 5),
                                              new SixLabors.Primitives.PointF[] {
                    new Vector2(10, 10),
                    new Vector2(200, 150),
                    new Vector2(50, 300)
                }));
                image.Save($"{path}/Dot.png");
            }
        }
Example #4
0
        public void ImageShouldBeOverlayedByPathDotted()
        {
            string path  = CreateOutputDirectory("Drawing", "Lines");
            var    image = new Image(500, 500);

            using (FileStream output = File.OpenWrite($"{path}/Dot.png"))
            {
                image
                .BackgroundColor(Color.Blue)
                .DrawLines(Pens.Dot(Color.HotPink, 5), new[] {
                    new Vector2(10, 10),
                    new Vector2(200, 150),
                    new Vector2(50, 300)
                })
                .Save(output);
            }
        }
Example #5
0
        public static IPen GetPen(this Cmdlet cmdlet, Pen penType, float width, string colorString)
        {
            Rgba32 rgbaColor = cmdlet.ParseColor(colorString);
            Color  color     = new Color(rgbaColor);

            switch (penType)
            {
            case Pen.Dash:
                return(Pens.Dash(color, width));

            case Pen.DashDot:
                return(Pens.DashDot(color, width));

            case Pen.DashDotDot:
                return(Pens.DashDotDot(color, width));

            case Pen.Dot:
                return(Pens.Dot(color, width));

            default:
                return(Pens.Solid(color, width));
            }
        }
Example #6
0
 /// <summary>
 /// Create a pen with a 'Dot' drawing patterns
 /// </summary>
 /// <param name="brush">The brush.</param>
 /// <param name="width">The width.</param>
 /// <returns>The Pen</returns>
 public static Pen Dot(IBrush <Color> brush, float width) => new Pen(Pens <Color> .Dot(brush, width));
Example #7
0
 /// <summary>
 /// Create a pen with a 'Dot' drawing patterns
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="width">The width.</param>
 /// <returns>The Pen</returns>
 public static Pen Dot(Color color, float width) => new Pen(Pens <Color> .Dot(color, width));
        /// <summary>
        /// 画点+画字=验证码byte[]
        /// </summary>
        /// <param name="code"></param>
        /// <param name="vCodeNum"></param>
        /// <param name="xx"></param>
        /// <param name="yy"></param>
        /// <returns></returns>
        public static byte[] GetValidCodeByte(string fontPath, out string code, int vCodeNum = 4, int xx = 80, int yy = 25)
        {
            var bb = default(byte[]);

            code = RndNum(vCodeNum);
            try
            {
                var content    = code;
                var dianWith   = 1;             //点宽度
                var xx_space   = 10;            //点与点之间x坐标间隔
                var yy_space   = 5;             //y坐标间隔
                var wenZiLen   = vCodeNum;      //文字长度
                var maxX       = xx / wenZiLen; //每个文字最大x宽度
                var prevWenZiX = 0;             //前面一个文字的x坐标
                var size       = maxX;          //字体大小

                //字体
                var install_Family = new FontCollection().Install(fontPath);
                //var install_Family = new FontCollection().Find("arial");
                var font = new Font(install_Family, size);  //字体

                //点坐标
                var listPath = new List <IPath>();
                for (int i = 0; i < xx / xx_space; i++)
                {
                    for (int j = 0; j < yy / yy_space; j++)
                    {
                        var position   = new Vector2(i * xx_space, j * yy_space);
                        var linerLine  = new LinearLineSegment(position, position);
                        var shapesPath = new SixLabors.Shapes.Path(linerLine);
                        listPath.Add(shapesPath);
                    }
                }

                //画图
                using (Image <Rgba32> image = new Image <Rgba32>(xx, yy))   //画布大小
                {
                    image.Mutate(x =>
                    {
                        var imgProc = x;

                        //逐个画字
                        for (int i = 0; i < wenZiLen; i++)
                        {
                            //当前的要输出的字
                            var nowWenZi = content.Substring(i, 1);

                            //文字坐标
                            var wenXY = new Vector2();
                            var maxXX = prevWenZiX + (maxX - size);
                            wenXY.X   = new Random().Next(prevWenZiX, maxXX);
                            wenXY.Y   = new Random().Next(0, yy - size);

                            prevWenZiX = Convert.ToInt32(Math.Floor(wenXY.X)) + size;

                            //画字
                            imgProc.DrawText(
                                nowWenZi,      //文字内容
                                font,
                                i % 2 > 0 ? Rgba32.HotPink : Rgba32.Red,
                                wenXY,
                                TextGraphicsOptions.Default);
                        }

                        //画点
                        imgProc.BackgroundColor(Rgba32.WhiteSmoke). //画布背景
                        Draw(
                            Pens.Dot(Rgba32.HotPink, dianWith),     //大小
                            new PathCollection(listPath)            //坐标集合
                            );
                    });
                    using (MemoryStream stream = new MemoryStream())
                    {
                        image.SaveAsPng(stream);
                        bb = stream.GetBuffer();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(bb);
        }