C# 绘图:绘制中间有孔的多边形的最佳方法是什么
我有一个由外边框和内边框定义的形状。如果没有内边框,则形状是实心的。如果有内部边界,我希望仅在两个边界之间定义多边形/路径;我不想绘制外部,然后用背景颜色绘制内部。
例如,如果我有一个由以下坐标定义的外部边框的正方形:
{0,0}, {20, 0}, {20,20}, {0, 20}
那么该正方形的大小为 20x20,其左下角位于原点。然后,该形状从中心切出一个三角形:
{10,10}, {15,10}, {15,15}
如何使用 WPF 或 GDI+ 创建包含该形状的路径?
I have a shape that is defined by an outer border and then an inner border. IF there is no inner boarder, the shape is solid. If there is an inner border I want the polygon/path to be defined only between the two borders; I don't want to draw the outside and then draw the inside in the background color.
For example, if I have a square defined by the following coordinates for the outside border:
{0,0}, {20, 0}, {20,20}, {0, 20}
Then that square which is 20x20 with its bottom left right corner on the origin. That shape then has a triangle cut out of the center:
{10,10}, {15,10}, {15,15}
How can I create a path that contains this shape using either WPF or GDI+?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 XAML 绘制该形状:(关键是使用
CombinedGeometry
和GeometryCombineMode="Exclude"
)You can draw that shape with XAML: (The key is to use a
CombinedGeometry
withGeometryCombineMode="Exclude"
)在 GDI+ 中,您可以将
FillPath()
或DrawPath()
与FillModeAlternate
结合使用。有一个非常接近您要求的示例 这里。
In GDI+, you can use
FillPath()
orDrawPath()
withFillModeAlternate
.There's an example pretty close to what you're asking for here.
只需使用背景颜色在主轮廓顶部绘制孔即可。看起来就像是真正的洞
编辑
如果您使用的 api 不支持漏洞,请使用此方法。这就是为什么我假设你在问
Just draw the holes on top of the main contour using the background color. It will look as if they were real holes
edit
use this approach if the api you are using does not support holes. Which is why I assume you are asking