首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有z阶的自交GraphicsPath

具有z阶的自交GraphicsPath
EN

Stack Overflow用户
提问于 2022-10-06 16:45:52
回答 1查看 41关注 0票数 1

我需要创建一个框架GraphicsPath,它的自我交叉给人一种z级的感觉:

用于获取图像的代码如下:

代码语言:javascript
复制
private void Example1(PaintEventArgs e) {
    Brush brush = new SolidBrush(Color.FromArgb(200, Color.LightBlue));

    GraphicsPath path1 = new GraphicsPath(FillMode.Winding);
    path1.AddLines(new Point[] {
        new Point(400, 200),
        new Point(400, 300),
        new Point(100, 300),
        new Point(100, 400),
        new Point(500, 400),
        new Point(500, 100)
    });
    e.Graphics.FillPath(brush, path1);
    e.Graphics.DrawPath(Pens.Blue, path1);

    GraphicsPath path2 = new GraphicsPath(FillMode.Winding);
    path2.AddLines(new Point[] {
        new Point(500, 100),
        new Point(200, 100),
        new Point(200, 500),
        new Point(300, 500),
        new Point(300, 200),
        new Point(400, 200)
    });
    e.Graphics.FillPath(brush, path2);
    e.Graphics.DrawPath(Pens.Blue, path2);
}

其中我独立地画了两条路。

我需要把它作为一个唯一的图形对象来处理,但是如果我加入了这些路径,我就会得到这样的图像:

示例代码:

代码语言:javascript
复制
private void Example2(PaintEventArgs e) {
    Brush brush = new SolidBrush(Color.FromArgb(200, Color.LightBlue));

    GraphicsPath path1 = new GraphicsPath(FillMode.Winding);
    path1.AddLines(new Point[] {
        new Point(400, 200),
        new Point(400, 300),
        new Point(100, 300),
        new Point(100, 400),
        new Point(500, 400),
        new Point(500, 100)
    });

    GraphicsPath path2 = new GraphicsPath(FillMode.Winding);
    path2.AddLines(new Point[] {
        new Point(500, 100),
        new Point(200, 100),
        new Point(200, 500),
        new Point(300, 500),
        new Point(300, 200),
        new Point(400, 200)
    });

    path1.AddPath(path2, true);
    e.Graphics.FillPath(brush, path1);
    e.Graphics.DrawPath(Pens.Blue, path1);
}

如果我使用StartFigure/CloseFigure,同样的问题。也许我可以结合使用SetMarkers方法和GraphicsPathIterator来解决这个问题,但这似乎是压倒性的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-07 06:54:38

我发现的最简单的方法是使用GraphicsPathIterator。通过这种方式,我可以在一条道路上存储更多的数字,并在绘画过程中具有所需的灵活性。唯一的缺点是油漆方法必须进行相应的修改。

下面是一个示例,其中我定义了路径,并对绘画进行了如下操作:

代码语言:javascript
复制
private void Example4(PaintEventArgs e) {
    Brush brush = new SolidBrush(Color.FromArgb(200, Color.LightBlue));

    GraphicsPath path = new GraphicsPath(FillMode.Winding);
    path.StartFigure();
    path.AddLines(new Point[] {
        new Point(400, 200),
        new Point(400, 300),
        new Point(100, 300),
        new Point(100, 400),
        new Point(500, 400),
        new Point(500, 100)
    });

    path.StartFigure();
    path.AddLines(new Point[] {
        new Point(500, 100),
        new Point(200, 100),
        new Point(200, 500),
        new Point(300, 500),
        new Point(300, 200),
        new Point(400, 200)
    });

    GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);
    GraphicsPath p = new GraphicsPath();
    while (pathIterator.NextSubpath(p, out bool isClosed) > 0) {
        e.Graphics.FillPath(brush, p);
        e.Graphics.DrawPath(Pens.Blue, p);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73977377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档