C# Image to PathGeometry

252 views Asked by At

I am trying to Convert an Image to a PathGeometry. I upload a picture, and then I do canny edge detection and now I want to convert that in to a PathGeometry. My over all plan it to fill it with different colors.

So I tried this :`public Shape MakeSape(Brush customColor, double[,] image) { Path graphPath = new Path();

        graphPath.Fill = customColor;
        graphPath.Stroke = Brushes.Black;
        PathFigure pf = new PathFigure();
        pf.StartPoint = new Point(0, 0);
        pf.IsClosed = true;
        int row = image.GetLength(0);
        int column = image.GetLength(1);

        for (int y = 0; y < row; y++)
        {
            for (int x = 0; x < column; x++)
            {
                if (image[y, x] >= LowThreshold)
                {
                    pf.Segments.Add(new LineSegment(new Point(x, y), true));
                }
            }

        }

        PathGeometry pg = new PathGeometry();
        pg.Figures.Add(pf);
        graphPath.Data = pg;

        ImageAsShape = graphPath;
        return graphPath;
    }` 

And that looked like it should work, but I am just getting all black.

0

There are 0 answers