我有以下

private bool IsPathVisible(Rectangle detectorRectangle, GraphicsPath path, Pen pen)
{
    path.Widen(pen);
    return IsPathVisible(detectorRectangle, path);
}


path点是同一点时,我收到OutOfMemoryException(使用Widen函数)。

我该如何管理?

最佳答案

用笔和加宽方法是一个错误。确保路径的起点与路径的终点不同。

这是一个演示:

private void panel1_Paint(object sender, PaintEventArgs e)
{
  //This works:
  using (GraphicsPath path = new GraphicsPath())
  {
    path.AddLine(new Point(16, 16), new Point(20, 20));
    path.Widen(Pens.Black);
    e.Graphics.DrawPath(Pens.Black, path);
  }

  //This does not:
  using (GraphicsPath path = new GraphicsPath())
  {
    path.AddLine(new Point(20, 20), new Point(20, 20));
    path.Widen(Pens.Black);
    e.Graphics.DrawPath(Pens.Black, path);
  }
}


这是向Microsoft报告的位置:GraphicsPath.Widen throw OutOfMemoryException if the path has a single point

09-25 15:53