GraphicsPath的和OutOfMemoryException异常异常、GraphicsPath、OutOfMemoryException

由网友(最好的我们)分享简介:我有以下private bool IsPathVisible(Rectangle detectorRectangle, GraphicsPath path, Pen pen){path.Widen(pen);return IsPathVisible(detectorRectangle, path);}在路径点是同...

我有以下

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

路径点是同一个点,我收到了OutOfMemoryException异常(使用拓宽函数)。

When path points are the same point, I receive a OutOfMemoryException (using Widen function).

我该如何管理呢?

推荐答案

这是用钢笔和拓宽方法的错误。确保你的路径和路径的终点的起始点是不一样的。

That's a bug with the pen and the widen method. Make sure your startpoint of the path and the endpoint of the path are not the same.

这是一个演示:

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);
  }
}

下面是它被报告给微软: GraphicsPath.Widen抛出OutOfMemoryException异常如果路径中有一个单点

Here is where it was reported to Microsoft: GraphicsPath.Widen throw OutOfMemoryException if the path has a single point

阅读全文

相关推荐

最新文章