示例#1
0
        public void Test_Draw()
        {
            using (IMagickImage image = new MagickImage(MagickColors.Fuchsia, 100, 100))
            {
                Drawables drawables = new Drawables()
                                      .FillColor(MagickColors.Red)
                                      .Rectangle(10, 10, 90, 90);

                IEnumerator enumerator = ((IEnumerable)drawables).GetEnumerator();
                Assert.IsTrue(enumerator.MoveNext());

                drawables.Draw(image);

                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
                ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
                ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);

                image.Draw(new Drawables()
                           .FillColor(MagickColors.Green)
                           .Rectangle(15, 15, 85, 85));

                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
                ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
                ColorAssert.AreEqual(MagickColors.Green, image, 15, 15);
                ColorAssert.AreEqual(MagickColors.Green, image, 85, 85);
                ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);
            }
        }
示例#2
0
            public void ShouldDrawTheDrawables()
            {
                using (var image = new MagickImage(MagickColors.Fuchsia, 100, 100))
                {
                    var drawables = new Drawables()
                                    .FillColor(MagickColors.Red)
                                    .Rectangle(10, 10, 90, 90);

                    drawables.Draw(image);

                    ColorAssert.Equal(MagickColors.Fuchsia, image, 9, 9);
                    ColorAssert.Equal(MagickColors.Red, image, 10, 10);
                    ColorAssert.Equal(MagickColors.Red, image, 90, 90);
                    ColorAssert.Equal(MagickColors.Fuchsia, image, 91, 91);

                    image.Draw(new Drawables()
                               .FillColor(MagickColors.Green)
                               .Rectangle(15, 15, 85, 85));

                    ColorAssert.Equal(MagickColors.Fuchsia, image, 9, 9);
                    ColorAssert.Equal(MagickColors.Red, image, 10, 10);
                    ColorAssert.Equal(MagickColors.Green, image, 15, 15);
                    ColorAssert.Equal(MagickColors.Green, image, 85, 85);
                    ColorAssert.Equal(MagickColors.Red, image, 90, 90);
                    ColorAssert.Equal(MagickColors.Fuchsia, image, 91, 91);
                }
            }
示例#3
0
        public byte[] Create(List <LabeleldValue> values)
        {
            var lineHeight = 12;
            var height     = values.Count * lineHeight + 4;

            using (var image = new MagickImage(new MagickColor("#56667A"), 260, height))
            {
                image.Depth = 64;

                var magic = new Drawables()
                            .FontPointSize(12)

                            .Font("Courier New")

                            .TextAlignment(TextAlignment.Left);

                for (int i = 0; i < values.Count; i++)
                {
                    magic.Text(2, 12 * (i + 1), $"{values[i].Label}: {values[i].Value}");
                }
                magic.FillColor(new MagickColor(MagickColors.White));
                magic.Draw(image);


                return(image.ToByteArray(MagickFormat.Png));
            }
        }
        private void DrawGridLines(MagickImage image)
        {
            var drawables = new Drawables();

            for (int x = 0; x < mapWidth; x++)
            {
                drawables.FillColor(MagickColors.DarkGray);
                drawables.Line(x * cellWidth, 0, x * cellWidth, ImageHeight);
            }
            for (int y = 0; y < mapHeight; y++)
            {
                drawables.FillColor(MagickColors.DarkGray);
                drawables.Line(0, y * cellHeight, ImageWidth, y * cellHeight);
            }
            drawables.Draw(image);
        }
        public void DrawInPaintingMasks(MagickImage mImage, List <Rectangle> maskRegions, MagickColor maskColor,
                                        double maskOversize = 0.0)
        {
            var drawables = new Drawables();

            drawables.StrokeColor(maskColor);
            drawables.StrokeOpacity(new Percentage(0));
            drawables.FillColor(maskColor);

            foreach (var maskRegion in maskRegions)
            {
                var(x, y, w, h) = (maskRegion.X, maskRegion.Y, maskRegion.Width, maskRegion.Height);
                drawables.Rectangle(x - maskOversize, y - maskOversize, x + w + maskOversize * 2.0,
                                    y + h + maskOversize * 2.0);
            }

            drawables.Draw(mImage);
        }
        private void DrawPlayers(MagickImage image)
        {
            var players   = playerRepository.GetAllPlayers();
            var drawables = new Drawables();

            foreach (var player in players)
            {
                drawables.FillColor(player.IsIt ? MagickColors.Red : MagickColors.Black);
                drawables.Ellipse(player.X * cellWidth + (cellWidth / 2), player.Y * cellHeight + (cellHeight / 2), cellWidth / 2, cellHeight / 2, 0, 360);
                var yPosition = player.Y < mapHeight - 2
                    ? player.Y * cellHeight + (cellHeight * 2)
                    : player.Y * cellHeight;

                drawables.FillColor(MagickColors.Black);
                drawables.TextAlignment(TextAlignment.Center);
                drawables.Text(player.X * cellWidth + (cellWidth / 2), yPosition, player.Name);
            }
            drawables.Draw(image);
        }
示例#7
0
        public byte[] CreateHeatmap(IEnumerable <RdfSession> sessions)
        {
            const int displayRadius = 40;
            const int groupRadius   = 10;

            var variations = sessions.SelectMany(s => s.Contains.Regions)
                             .SelectMany(r => r.Contains.Variations).ToList();
            var points = variations
                         .SelectMany(v => v.Contains.Events)
                         .Where(e => e is RdfSingleClickMouseEvent).ToList();

            int maxNearestCount = points.Count == 0
                ? 0
                : points.Max(point => points
                             .Count(p => Math.Abs(point.InRegionX - p.InRegionX) <= groupRadius &&
                                    Math.Abs(point.InRegionY - p.InRegionY) <= groupRadius));

            int width  = variations.Max(v => (int)v.Width);
            int height = points.Max(p => p.InRegionY + 100);

            using var img = new MagickImage(MagickColors.Transparent, width, height);
            var drawables = new Drawables();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var intensity = points
                                    .Select(point =>
                                            Math.Sqrt(Math.Pow(x - point.InRegionX, 2) +
                                                      Math.Pow(y - point.InRegionY, 2)))
                                    .Where(distance => distance < displayRadius)
                                    .Sum(distance => 1.0d - distance / displayRadius);

                    intensity = Math.Abs(intensity) < 0.01 ? 0 : intensity / maxNearestCount;

                    drawables.FillColor(_gradientProvider.GetColorAtValue(intensity)).Point(x, y);
                }
            }

            drawables.Draw(img);
            return(img.ToByteArray(MagickFormat.Png));
        }