C# 图像到 PathGeometry

发布于 2025-01-13 08:57:11 字数 994 浏览 0 评论 0原文

我正在尝试将图像转换为 PathGeometry。我上传一张图片,然后进行精明的边缘检测,现在我想将其转换为 PathGeometry。我的总体计划是用不同的颜色填充它。

所以我尝试了这个:`public Shape MakeSape(Brush customColor, double[,] image) { 路径 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;
    }` 

看起来应该可行,但我只是变得全黑了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文