Example #1
0
        Control MetricsPreview()
        {
            metricsPreview = new Drawable {
                Size = new Size(200, 100)
            };
            metricsPreview.Paint += (sender, pe) => {
                var size  = pe.Graphics.MeasureString(selectedFont, preview.Text);
                var scale = this.ParentWindow.Screen.Scale;

                var ypos = Math.Max(0, (selectedFont.Ascent * scale) - size.Height);
                ypos += Math.Max(0, (metricsPreview.Size.Height - (selectedFont.LineHeight * scale)) / 2);

                var baseline = ypos + (selectedFont.Baseline * scale);
                pe.Graphics.DrawLine(Pens.Black(), 0, baseline, 200, baseline);

                pe.Graphics.DrawText(selectedFont, Colors.Black, 0, ypos, preview.Text);

                var ascender = baseline - selectedFont.Ascent * scale;
                pe.Graphics.DrawLine(Pens.Blue(), 0, ascender, 200, ascender);

                var descender = baseline + selectedFont.Descent * scale;
                pe.Graphics.DrawLine(Pens.Red(), 0, descender, 200, descender);

                var xheight = baseline - selectedFont.XHeight * scale;
                pe.Graphics.DrawLine(Pens.Green(), 0, xheight, 200, xheight);

                var lineheight = ypos + selectedFont.LineHeight * scale;
                pe.Graphics.DrawLine(Pens.Orange(), 0, lineheight, 200, lineheight);
            };
            return(metricsPreview);
        }
Example #2
0
        public Task Initialize(MatrixParams mparams)
        {
            this.sizex = mparams.SizeX;
            this.sizey = mparams.SizeY;
            var size = new Size((int)this.sizex, (int)this.sizey);

            this.pbuf = new RGBPixel[sizex, sizey];

            Font font  = null;
            var  fonts = new FontCollection();

            foreach (var f in fontpfade)
            {
                if (System.IO.File.Exists(f))
                {
                    fonts.Install(f);
                }
            }
            try{
                font = SystemFonts.CreateFont(this.FontFamily, this.Size, this.Style);
            }
            catch (Exception d) {}
            FontRectangle sz     = TextMeasurer.Measure(this.Text, new RendererOptions(font));
            Size          _tsize = new Size(Convert.ToInt32(sz.Width + 1), Convert.ToInt32(sz.Height + 1));

            this._image = new Image <Rgba32>(_tsize.Width, _tsize.Height);
            _image.Mutate(ctx =>
            {
                //ctx.Fill(Rgba32.Black);
                ctx.DrawText(this.Text, font, Brushes.Solid(Color.White), Pens.Solid(Color.Beige, 1), PointF.Empty);
            });

            _tpos = _image.Width / 2;
            return(Task.CompletedTask);
        }
Example #3
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 #4
0
        public void PathExtendingOffEdgeOfImageShouldNotBeCropped()
        {
            string path = this.CreateOutputDirectory("Drawing", "Path");

            using (var image = new Image <Rgba32>(256, 256))
            {
                image.Fill(Rgba32.Black);
                var pen = Pens.Solid(Rgba32.White, 5f);

                for (int i = 0; i < 300; i += 20)
                {
                    image.DrawLines(pen, new Vector2[] { new Vector2(100, 2), new Vector2(-10, i) });
                }

                using (FileStream output = File.OpenWrite($"{path}/ClippedLines.png"))
                {
                    image
                    .Save(output);
                }
                using (PixelAccessor <Rgba32> sourcePixels = image.Lock())
                {
                    Assert.Equal(Rgba32.White, sourcePixels[0, 90]);
                }
            }
        }
Example #5
0
        public DistractedBoyfriendMemeGen(BotState state)
        {
            _botState = state;
            _template = new MemeTemplate("DistractedBoyfriend.jpg",
                                         new MultiBoundingBox(
                                             new TextBoundingBox(1338, 823, 500, 260)
            {
                Brush = Brushes.Solid(Rgba32.White),
                Pen   = Pens.Solid(Rgba32.Black, 2),
                Font  = font
            }, new ImageBoundingBox(1338, 703, 500, 500)),

                                         new MultiBoundingBox(
                                             new TextBoundingBox(1874, 829, 440, 260)
            {
                Brush = Brushes.Solid(Rgba32.White),
                Pen   = Pens.Solid(Rgba32.Black, 2),
                Font  = font
            }, new ImageBoundingBox(1844, 689, 500, 500)),
                                         new MultiBoundingBox(
                                             new TextBoundingBox(487, 1016, 500, 260)
            {
                Brush = Brushes.Solid(Rgba32.White),
                Pen   = Pens.Solid(Rgba32.Black, 2),
                Font  = font
            }, new ImageBoundingBox(487, 876, 500, 500)));
        }
Example #6
0
        public void CanDrawWithoutMemoryException()
        {
            int width  = 768;
            int height = 438;

            // Creates a new image with empty pixel data.
            using (var image = new Image <Rgba32>(width, height))
            {
                FontFamily family = SystemFonts.Find("verdana");
                Font       font   = family.CreateFont(48, FontStyle.Bold);

                // The options are optional
                TextGraphicsOptions options = new TextGraphicsOptions()
                {
                    TextOptions = new TextOptions()
                    {
                        ApplyKerning        = true,
                        TabWidth            = 8,                         // a tab renders as 8 spaces wide
                        WrapTextWidth       = width,                     // greater than zero so we will word wrap at 100 pixels wide
                        HorizontalAlignment = HorizontalAlignment.Center // right align
                    }
                };

                IBrush brush = Brushes.Solid(Color.White);
                IPen   pen   = Pens.Solid(Color.White, 1);
                string text  = "sample text";

                // Draw the text
                image.Mutate(x => x.DrawText(options, text, font, brush, pen, new PointF(0, 100)));
            }
        }
Example #7
0
        public static void AddPointsToImage(Image <Rgba32> image, List <Puntje> lijstje)
        {
            foreach (var pnt in lijstje)
            {
                var pntX = ((pnt.X + 1.0) / 2.0) * image.Width;
                var pntY = ((pnt.Y + 1.0) / 2.0) * image.Height;

                int pntXInt = (int)pntX;
                int pntYInt = (int)pntY;


                Rgba32 color = Rgba32.Black;


                if (pnt.PuntType == PuntType.Oranje)
                {
                    color = new Rgba32(255, 128, 0);
                }
                else
                {
                    color = new Rgba32(0, 0, 255);
                }

                var pen  = Pens.Solid(Rgba32.White, 2);
                var poly = new SixLabors.Shapes.EllipsePolygon((float)pntX, (float)pntY, 3);
                image.Mutate(t => t.Fill(color, poly));
                image.Mutate(t => t.Draw(pen, poly));


                image[pntXInt, pntYInt] = color;
            }
        }
Example #8
0
        public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions()
        {
            this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path);

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(6, this.img.ProcessorApplications.Count);
        }
Example #9
0
 public PigeonMemeGen(BotState state)
 {
     _botState = state;
     _template = new MemeTemplate("Pigeon.jpg",
                                  new MultiBoundingBox(
                                      new TextBoundingBox(196, 181, 350, 120)
     {
         CenterWidth  = true,
         CenterHeight = true,
         Brush        = Brushes.Solid(Rgba32.White),
         Pen          = Pens.Solid(Rgba32.Black, 2),
         Font         = font
     }, new ImageBoundingBox(190, 196, 375, 375)),
                                  new MultiBoundingBox(
                                      new TextBoundingBox(738, 144, 300, 220)
     {
         CenterWidth  = true,
         CenterHeight = true,
         Brush        = Brushes.Solid(Rgba32.White),
         Pen          = Pens.Solid(Rgba32.Black, 2),
         Font         = font
     }, new ImageBoundingBox(780, 148, 215, 215)),
                                  new TextBoundingBox(277, 741, 694, 80)
     {
         CenterWidth  = true,
         CenterHeight = true,
         Brush        = Brushes.Solid(Rgba32.White),
         Pen          = Pens.Solid(Rgba32.Black, 2),
         Font         = font
     });
 }
Example #10
0
        public void DrawForEachACharacterWhenPenSetAndFillFroEachWhenBrushSet()
        {
            this.operations.DrawText(
                this.otherTextOptions,
                "123",
                this.Font,
                Brushes.Solid(Color.Red),
                Pens.Dash(Color.Red, 1),
                Vector2.Zero);

            var processor = this.Verify <DrawTextProcessor>(0);

            Assert.Equal("123", processor.Text);
            Assert.Equal(this.Font, processor.Font);
            var brush = Assert.IsType <SolidBrush>(processor.Brush);

            Assert.Equal(Color.Red, brush.Color);
            Assert.Equal(PointF.Empty, processor.Location);
            var penBrush = Assert.IsType <SolidBrush>(processor.Pen.StrokeFill);

            Assert.Equal(Color.Red, penBrush.Color);
            Assert.Equal(1, processor.Pen.StrokeWidth);
            Assert.NotEqual(this.textOptions, processor.Options.TextOptions);
            Assert.NotEqual(this.options, processor.Options.GraphicsOptions);
        }
Example #11
0
        public void TestNoAADrawLineDiagonalFewerPoints()
        {
            // red line, 1px per row, diagonal top left to bottom right
            // but bottom left and top right pixels are empty
            string specification = ".100\n" + Enumerable
                                   .Range(1, 98)
                                   .Select(x => new string('.', 100 - x - 1) + "R")
                                   .Join("\n");

            this.ExpectedImage = new TestImage(100, 100, Color.Black)
                                 .FillPattern(specification, Color.Black)
                                 .Finish();

            var path = new[]
            {
                new PointF(1, 98),
                new PointF(1, 98),
                new PointF(98, 1),
            };

            this.ActualImage = new Image <Rgb24>(Configuration.Default, 100, 100, Color.Black);
            this.ActualImage.Mutate(x => x.NoAA().DrawLines(Pens.Solid(Color.Red, 1f), path));

            this.AssertImagesEqual();
        }
Example #12
0
        public void DrawForEachACharachterWhenPenSet()
        {
            this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true));

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
            Assert.IsType <DrawPathProcessor <Rgba32> >(this.img.ProcessorApplications[0].processor);
        }
Example #13
0
        public void DrawForEachACharachterWhenPenSetDefaultOptions()
        {
            this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero);

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
            Assert.IsType <DrawPathProcessor <Color> >(this.img.ProcessorApplications[0].processor);
        }
Example #14
0
        public void DrawLines_DashDotDot <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.DashDotDot(color, thickness);

            DrawLinesImpl(provider, colorName, alpha, thickness, antialias, pen);
        }
Example #15
0
        public void DrawForEachACharachterWhenPenSetDefaultOptions()
        {
            this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path);

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[0].processor);
        }
Example #16
0
        public void BrushAppliesBeforPenDefaultOptions()
        {
            this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), this.path);

            var processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
        }
Example #17
0
        public void DrawForEachACharacterWhenPenSet()
        {
            this.operations.DrawText(new TextGraphicsOptions {
                Antialias = true
            }, "123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero);

            this.Verify <DrawTextProcessor>(0);
        }
Example #18
0
        public void TestColorAssertFails2()
        {
            var bitmap = new Image <Rgb24>(200, 200);

            bitmap.Mutate(g => { g.DrawRectangle(Pens.Solid(Color.Red, 1), 20, 0, 180, 200); });

            Assert.ThrowsException <AssertFailedException>(() => Assert.That.ImageColorsWellDistributed(bitmap));
        }
Example #19
0
        public int x, y; // Параметры фигуры (вектор)

        #endregion Fields

        #region Constructors

        public Figure(Pens pen, int X, int Y, int x, int y)
        {
            this.pen = pen;
            this.X = X;
            this.Y = Y;
            this.x = x;
            this.y = y;
        }
Example #20
0
        public void DrawForEachACharachterWhenPenSet()
        {
            this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true));

            var processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
            this.Verify <FillRegionProcessor <Rgba32> >(2);
        }
Example #21
0
        public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions()
        {
            this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero);

            var processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
            this.Verify <FillRegionProcessor <Rgba32> >(2);
        }
Example #22
0
        public void Delete(int id)
        {
            Pens info = db.Penses.Find(id);

            if (info != null)
            {
                db.Penses.Remove(info);
            }
        }
Example #23
0
        public void BrushAppliesBeforPenDefaultOptions()
        {
            this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero);

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(2, this.img.ProcessorApplications.Count);
            Assert.IsType <FillRegionProcessor <Color> >(this.img.ProcessorApplications[0].processor);
            Assert.IsType <DrawPathProcessor <Color> >(this.img.ProcessorApplications[1].processor);
        }
Example #24
0
        public void BrushAppliesBeforPenDefaultOptions()
        {
            this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path);

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(2, this.img.ProcessorApplications.Count);
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[0].processor);
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[1].processor);
        }
Example #25
0
        public void DrawForEachACharacterWhenPenSet()
        {
            this.operations.DrawText(this.otherTextOptions, "123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero);

            var processor = this.Verify <DrawTextProcessor>(0);

            Assert.NotEqual(this.textOptions, processor.Options.TextOptions);
            Assert.NotEqual(this.options, processor.Options.GraphicsOptions);
        }
Example #26
0
        public void DrawForEachACharachterWhenPenSetDefaultOptions()
        {
            this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), this.path);

            FillRegionProcessor <Rgba32> processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
            this.Verify <FillRegionProcessor <Rgba32> >(2);
        }
Example #27
0
        public ActionResult Deletep(int id)
        {
            Pens PensId = dbp.Penses.Find(id);

            dbp.Penses.Remove(PensId);
            dbp.SaveChanges();
            ViewBag.Operation = "Удаление";
            return(View(PensId));
        }
Example #28
0
        public void DrawForEachACharacterWhenPenSetAndNotBrushDefaultOptions()
        {
            this.operations.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero);

            var processor = this.Verify <DrawTextProcessor>(0);

            Assert.Equal(this.textOptions, processor.Options.TextOptions);
            Assert.Equal(this.options, processor.Options.GraphicsOptions);
        }
Example #29
0
        public TextureInfo ConstructTextureWithGpxTrack(TileRange tiles, BoundingBox bbox, string fileName,
                                                        TextureImageFormat mimeType, IEnumerable <GeoPoint> gpxPoints, bool drawGpxVertices = false, Rgba32 color = default(Rgba32), float lineWidth = 5f)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.Tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel, tiles.TileSize);
            var tilesBbox     = GetTilesBoundingBox(tiles);
            int xOffset       = (int)(tilesBbox.xMin - projectedBbox.xMin);
            int yOffset       = (int)(tilesBbox.yMin - projectedBbox.yMin);


            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.TileSize;

            var pointsOnTexture = gpxPoints
                                  .Select(pt => TileUtils.PositionToGlobalPixel(new LatLong(pt.Latitude, pt.Longitude), zoomLevel, tiles.TileSize))
                                  .Select(pt => new PointF((float)(pt.X - (int)projectedBbox.xMin), (float)(pt.Y - (int)projectedBbox.yMin)));


            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                foreach (var tile in tiles.Tiles)
                {
                    using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        outputImage.Mutate(o => o
                                           .DrawImage(tileImg, new Point(x, y), 1f)
                                           );
                    }
                }

                outputImage.Mutate(o => o
                                   .DrawLines(color == default(Rgba32) ? new Rgba32(1, 0, 0, 1f) : color, lineWidth, pointsOnTexture.ToArray())
                                   );

                if (drawGpxVertices)
                {
                    PathCollection pc = new PathCollection(pointsOnTexture.Select(p => new EllipsePolygon(p, new SizeF(10f, 10f))));
                    outputImage.Mutate(o => o.Draw(GraphicsOptions.Default, Pens.Solid(Rgba32.Violet, 3), pc));
                }

                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                outputImage.Save(fileName);
            }

            return(new TextureInfo(fileName, mimeType, (int)projectedBbox.Width, (int)projectedBbox.Height, zoomLevel,
                                   projectedBbox));
        }
Example #30
0
        public async Task Pen(Pens pen)
        {
            await this.SendComCommand("G4 P50"); // pause

            await this.SendComCommand(pen == Pens.down? "M280P0S0" : "M280P0S30");

            await this.SendComCommand("G4 P50"); // pause

            this.PenIsUp = pen == Pens.up;
        }
Example #31
0
        public object Editp(Pens edit)
        {
            string str = edit.Size.SizeConventer();

            edit.Size             = str;
            dbp.Entry(edit).State = EntityState.Modified;
            dbp.SaveChanges();
            ViewBag.Operation = "Редактирование";
            return(View("Result"));
        }
Example #32
0
 public MyEllipse(Pens pen, int X, int Y, int x, int y)
     : base(pen, X, Y, x, y)
 {
 }
Example #33
0
 public MyRectangle(Pens pen, int X, int Y, int x, int y)
     : base(pen, X, Y, x, y)
 {
 }
Example #34
0
 public MyLine(Pens pen, int X, int Y, int x, int y)
     : base(pen, X, Y, x, y)
 {
 }