示例#1
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 DrawBboxes(byte[] photo, Bbox[] bboxes, ref Image img)
        {
            using (var image = new MagickImage(photo))
            {
                var drawables = new Drawables();
                drawables.StrokeWidth(ViewImage.Source.Height >= 1000 ? 8 : 2);
                drawables.FillColor(MagickColor.FromRgba(255, 255, 255, 0));
                drawables.StrokeColor(MagickColor.FromRgb(255, 0, 0));

                foreach (var bbox in bboxes)
                {
                    drawables.Rectangle(bbox.X,
                                        bbox.Y,
                                        bbox.X + bbox.Width,
                                        bbox.Y + bbox.Height
                                        );
                }

                image.Draw(drawables);

                using (var ms = new MemoryStream(image.ToByteArray()))
                {
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmap.StreamSource = ms;
                    bitmap.EndInit();
                    img.Source = bitmap;
                }
            }
        }
示例#3
0
        public void At(int seconds)
        {
            using (var image = new MagickImage(new MagickColor("#000000"), GraphSize, GraphSize))
            {
                image.Format = MagickFormat.Png;
                var d = new Drawables();
                d.FillColor(MagickColors.Blue);

                bool any = false;

                foreach (var point in points)
                {
                    int x = Shift(point.X + point.Vx * seconds);
                    int y = Shift(point.Y + point.Vy * seconds);

                    if (x >= 0 && y >= 0 && x <= GraphSize && y <= GraphSize)
                    {
                        any = true;
                        d.Rectangle(x, y, x + 1, y + 1);
                    }
                }

                if (any)
                {
                    image.Draw(d);
                    image.Write($@"C:\dev\aoc\2018\10\output\{seconds}.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);
        }
        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);
        }
示例#6
0
        public Drawables GetFramePath()
        {
            var drawables = new Drawables().Path(
                new PathLineToAbs(Top, LeftTop, LeftBottom, Bottom, RightBottom, RightTop, Top));

            drawables.StrokeColor(FrameColor);
            drawables.FillColor(FillColor);
            drawables.StrokeWidth(Scale(FrameThickness));

            return(drawables);
        }
示例#7
0
        static public bool SaveMazeImage(int[,] grid, List <Coordinate> path, int wallThickness, int pathThickness, string fileName)
        {
            int width  = grid.GetLength(0); //dimension 0 of grid is width
            int height = grid.GetLength(1); //dimension 1 of grid is height

            using (MagickImage image = new MagickImage(new MagickColor("#ff00ff"), wallThickness * width, wallThickness * height))
            {
                Drawables draw = new Drawables(); //Hold the changes to be added to the image.
                draw.StrokeWidth(0);
                draw.StrokeColor(colors[0]);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        draw.FillColor(colors[grid[x, y]]).
                        Rectangle(x * wallThickness, y * wallThickness, (x + 1) * wallThickness, (y + 1) * wallThickness);
                    }
                }

                draw.StrokeColor(colors[colors.Length - 1]).StrokeWidth(pathThickness);
                for (int i = 0; i < path.Count - 1; i++)
                {
                    //Use center points in grid for drawing path
                    Coordinate startPoint = new Coordinate(
                        path[i].x * wallThickness + wallThickness / 2,
                        path[i].y * wallThickness + wallThickness / 2
                        );
                    Coordinate endPoint = new Coordinate(
                        path[i + 1].x * wallThickness + wallThickness / 2,
                        path[i + 1].y * wallThickness + wallThickness / 2
                        );
                    draw.Line(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
                }

                // Draw a border around the image
                draw.FillOpacity(new Percentage(0));
                draw.StrokeColor(colors[1]).StrokeWidth(4);
                draw.Rectangle(0, 0, wallThickness * width, wallThickness * height);
                //Commit draw calls to the image itself
                image.Draw(draw);
                //Save the Image
                image.Format = MagickFormat.Png;
                image.Write($"{fileName}.png");
            }
            return(true);
        }
        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);
        }
示例#9
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));
        }
        public static MagickImage GetImage()
        {
            if (!IsInitialized)
            {
                return(null);
            }

            var img = new MagickImage(background);

            if (Foreground > 0)
            {
                if (Foreground == 1)
                {
                    img.Composite(circular, CompositeOperator.Over);
                }
                if (Foreground == 2)
                {
                    img.Composite(rectangular, CompositeOperator.Over);
                }
            }

            img.Composite(logo_main, CompositeOperator.Over);
            img.Composite(logo_stripes, CompositeOperator.Over);

            var d = new Drawables();

            d.FontPointSize(FontSize);
            d.Font(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/Windows/Fonts/SFProDisplay-BlackItalic.ttf"));
            d.TextAlignment(TextAlignment.Center);
            d.TextAntialias(true);
            d.FillColor(new MagickColor("#000F"));
            d.Text(92, 154, Name == "" ? " " : Name);
            d.Text(93, 154, Name == "" ? " " : Name);
            d.Text(94, 154, Name == "" ? " " : Name);
            d.Text(92, 155, Name == "" ? " " : Name);
            d.Text(94, 155, Name == "" ? " " : Name);
            d.Text(92, 156, Name == "" ? " " : Name);
            d.Text(93, 156, Name == "" ? " " : Name);
            d.Text(94, 156, Name == "" ? " " : Name);
            d.FillColor(new MagickColor("#00ADFFFF"));
            d.Text(93, 155, Name == "" ? " " : Name);

            img.Draw(d);

            if (Color != 0)
            {
                if (Color == 1)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-75 * 100 / 180) + 100));
                }
                if (Color == 2)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-155 * 100 / 180) + 100));
                }
                if (Color == 3)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((70 * 100 / 180) + 100));
                }
                if (Color == 4)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((-180 * 100 / 180) + 100));
                }
                if (Color == 5)
                {
                    img.Modulate(new Percentage(100), new Percentage(100), new Percentage((140 * 100 / 180) + 100));
                }
            }

            return(img);
        }
示例#11
0
        public Perceptron Renderizar(ExemploCollection exemplos, int resX, int resY, string filename)
        {
            if (Entradas != 2)
            {
                throw new FormatException("Só é possível gerar o gráfico com um perceptron de duas entradas");
            }
            Console.WriteLine("Gerando gráfico...");
            MagickColor
                activeC       = MagickColor.FromRgb(72, 187, 133),
                inactiveC     = MagickColor.FromRgb(240, 106, 133),
                pointActive   = MagickColor.FromRgb(0, 255, 0),
                pointInactive = MagickColor.FromRgb(255, 0, 0);

            ushort[]
            active = new ushort[] { activeC.R, activeC.G, activeC.B },
            inactive      = new ushort[] { inactiveC.R, inactiveC.G, inactiveC.B };
            using var img = new MagickImage(MagickColor.FromRgb(0, 0, 0), resX, resY);
            var pxls = img.GetPixelsUnsafe();
            var draw = new Drawables();

            double[] praTestar = new double[Entradas];
            for (int x = 0; x < img.Width; x++)
            {
                praTestar[0] = ((double)x).Map(0, img.Width, 0, 1);
                for (int y = 0; y < img.Height; y++)
                {
                    praTestar[1] = ((double)y).Map(0, img.Height, 1, 0);
                    pxls.SetPixel(x, y, Testar(praTestar) ? active : inactive);
                }
            }

            var pointSize = Math.Min(img.Width, img.Height) / 25;

            int acertos = 0;

            for (int i = 0; i < exemplos.Count; i++)
            {
                var rad = i < QuantTreinamento ? pointSize / 3 : pointSize / 10;
                if (Testar(exemplos[i]) == exemplos[i].Saída)
                {
                    acertos++;
                }
                draw.FillColor(exemplos[i].Saída ? pointActive : pointInactive)
                .Ellipse(exemplos[i].Entradas[0].Map(0, exemplos.Máximos[0], 0, img.Width), exemplos[i].Entradas[1].Map(0, exemplos.Máximos[1], img.Height, 0), rad, rad, 0, 360);
            }

            var margin = 15;

            draw.FillColor(MagickColor.FromRgb(0, 0, 0))
            .Font("Consolas")
            .FontPointSize(pointSize)
            .TextAlignment(TextAlignment.Left)
            .Text(margin, img.Height - margin, "0")
            .Text(margin, margin + pointSize, exemplos.Máximos[1].ToString())
            .Text(margin, img.Height / 2, exemplos.Títulos[1])
            .TextAlignment(TextAlignment.Right)
            .Text(img.Width - margin, img.Height - margin, exemplos.Máximos[0].ToString())
            .TextAlignment(TextAlignment.Center)
            .Text(img.Width / 2, img.Height - margin, exemplos.Títulos[0])
            .Text(img.Width / 2, margin + pointSize, $"{Math.Floor(PropTreinamento * 100)}% de treinamento; {Math.Floor(((float)acertos / exemplos.Count) * 100)}% de acertos")
            .FillColor(MagickColor.FromRgb(255, 255, 255))
            .Line(margin / 2, 0, margin / 2, img.Height)
            .Line(0, img.Height - margin / 2, img.Width, img.Height - margin / 2)
            .Draw(img);
            img.Write(filename);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Process.Start("explorer", filename);
            }
            Console.WriteLine($"Gráfico gerado e salvo no arquivo {filename}");
            return(this);
        }