【问题标题】:GraphicsPath AddLine creates unexpected pathGraphicsPath AddLine 创建意外路径
【发布时间】:2016-01-28 21:45:40
【问题描述】:

我正在尝试使用 GraphicsPath 绘制类似图像的“文件夹”。

我创建路径的功能如下:

Public Function FolderRect(ByRef r As Rectangle) As System.Drawing.Drawing2D.GraphicsPath

    Dim p As New System.Drawing.Drawing2D.GraphicsPath

    Dim iTabWidth As Integer = 30
    Dim iTabHeight As Integer = 12

    With p
        Call p.AddLine(r.Left, r.Top, r.Left + iTabWidth, r.Top)
        Call p.AddLine(r.Left + iTabWidth, r.Top, r.Left + iTabWidth, r.Top + iTabHeight)
        Call p.AddLine(r.Left + iTabWidth, r.Top + iTabHeight, r.Right, r.Top + iTabHeight)
        Call p.AddLine(r.Right, r.Top + iTabHeight, r.Right, r.Bottom)
        Call p.AddLine(r.Right, r.Bottom, r.Left, r.Bottom)
        Call p.AddLine(r.Left, r.Bottom, r.Left, r.Top)

        Call p.CloseFigure()
    End With

    Return p

End Function

代码在我看来是正确的,但结果不是我所期望的:

(我使用图像编辑器创建了“正确”版本)。

这可能是 GraphicsPath 中的错误吗?

这就是 PathPoints 的样子:

这就是“r”的样子:

【问题讨论】:

  • 我看错了。我以为你追求有角度/斜面的外观。如果我使用你的代码,我会得到方形标签。我不明白这将如何产生斜面
  • 别修了,看起来不错。
  • 通过绘制最后几行而不是 p.CloseFigure() 来尝试它可能不会像您期望的那样关闭它。
  • @Plutonix 你还有你的“有角度的”代码吗?我真的很想使用它。很遗憾,你删除了它。
  • @DerekTomes 删除 p.CloseFigure() 并没有改变任何东西。

标签: vb.net system.drawing graphicspath


【解决方案1】:

图形路径几乎可以肯定是正确的。您可以通过查看图形路径的 PathPoints 属性来验证这一点。

绘制图形路径时可能存在一些舍入错误。尝试使路径与目标位图大小相同。

【讨论】:

  • 我无法使路径与目标位图的大小相同。我添加了 PathPoints 的屏幕截图。你认为这可能是正确的吗?
  • 您显示的路径点没有斜线。您可以将 tabwidth 更改为更大或更小,看看是否会有所改善。
  • 更改标签宽度并没有改变任何东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 2019-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多