C# GDI Drawing2D 帮助

发布于 2024-08-27 21:02:13 字数 108 浏览 5 评论 0原文

我可以使用哪些 GDI 方法来绘制下图中所示的蓝色形状?中心必须是透明的。

替代文字

What GDI methods can I use to draw the blue shape shown in the image below? The center must be transparent.

alt text

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-09-03 21:02:13

有多种方法,但您可能需要使用以下方法:

FillRectangle
FillPolygon
DrawLine

因为看起来您的形状可以简化为一个矩形和两个多边形,然后用几条线勾勒出轮廓。

这是我的想法的一个非常简单且硬编码的示例:

Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
    Dim g As Graphics = e.Graphics

    g.FillRectangle(Brushes.Aqua, New Rectangle(10, 10, 10, 90))
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 10), _
        New Point(20, 10), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 100), _
        New Point(20, 100), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.DrawLine(Pens.Black, New Point(10, 10), New Point(10, 100))
    g.DrawLine(Pens.Black, New Point(10, 100), New Point(20, 100))
    g.DrawLine(Pens.Black, New Point(20, 100), New Point(40, 50))
    g.DrawLine(Pens.Black, New Point(40, 50), New Point(20, 10))
    g.DrawLine(Pens.Black, New Point(20, 10), New Point(10, 10))

...

There are a number of ways but you'll probably want to use the following:

FillRectangle
FillPolygon
DrawLine

since it looks like your shape can be reduced to a rectangle and two polygons and then outlined by a few lines.

Here is a really simple and hard-coded example of what i was thinking:

Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
    Dim g As Graphics = e.Graphics

    g.FillRectangle(Brushes.Aqua, New Rectangle(10, 10, 10, 90))
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 10), _
        New Point(20, 10), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 100), _
        New Point(20, 100), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.DrawLine(Pens.Black, New Point(10, 10), New Point(10, 100))
    g.DrawLine(Pens.Black, New Point(10, 100), New Point(20, 100))
    g.DrawLine(Pens.Black, New Point(20, 100), New Point(40, 50))
    g.DrawLine(Pens.Black, New Point(40, 50), New Point(20, 10))
    g.DrawLine(Pens.Black, New Point(20, 10), New Point(10, 10))

...

王权女流氓 2024-09-03 21:02:13

我假设 GDI+ 又名 System.Drawing 命名空间。

最好的办法是查看 System.Drawing.Drawing2d.GraphicsPath 类:

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx

您需要确保关闭路径以获得空心效果。

Im assuming GDI+ here aka System.Drawing namespace.

The best thing to do is to look at System.Drawing.Drawing2d.GraphicsPath class :

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx

You need to make sure you close the path to get the hollow effect.

怀中猫帐中妖 2024-09-03 21:02:13

使用位图绘制不是更容易吗?无论如何,这就是他们的目的:)。

Wouldn't it just be easier to draw it using a bitmap? That's what they're for anyway :).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文