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;
                }
            }
        }
示例#2
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");
                }
            }
        }
示例#3
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);
        }