GraphicsPath 和 OutOfMemoryException
我有以下情况
private bool IsPathVisible(Rectangle detectorRectangle, GraphicsPath path, Pen pen)
{
path.Widen(pen);
return IsPathVisible(detectorRectangle, path);
}
当 path
点是同一点时,我收到 OutOfMemoryException (使用 Widen
函数)。
我该如何管理它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是笔和加宽方法的错误。确保路径的起点和路径的终点不相同。
这是一个演示:
这是向 Microsoft 报告的位置: GraphicsPath.Widen 如果路径有一个点,则抛出 OutOfMemoryException
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.
This is a demonstration:
Here is where it was reported to Microsoft: GraphicsPath.Widen throw OutOfMemoryException if the path has a single point
我也曾遭受过这种异常的困扰。建议如下:
在扩大之前保存点,以查看导致 OutOfMemoryException 的确切点:
您可能会看到可能存在具有相同坐标的后续点。他们实际上造成了问题。
此外,GraphicsPath 可以由多个子路径组成。为了进行可靠的命中测试,我建议执行以下操作:
然后您只需为区域调用 IsVisible 来查找是否有任何区域被命中
I've also been suffering from this exception. Recommendations are as following:
Save the points before widening to see exact points that cause OutOfMemoryException:
What you might see is that there are probably consequent points that have the same coordinates. They are actually causing the problem.
Also, GraphicsPath can consist of multiple subpaths. To make a reliable hit testing, I would recommend the following:
Then you simply call IsVisible for regions to find if any of them is hit
如果路径
IsPoint
,则不进行加宽操作。if the path
IsPoint
, don't do Widen.以下代码会导致 .Net 4.0(以及可能更高版本)中的 DrawPath 出现 OutOfMemory。
我设法使用 LineCap.Flat 而不是 LineCap.NoAnchor 绕过它:
The following code causes OutOfMemory in DrawPath in .Net 4.0 (and possibly higher).
I was managed to bypass it using LineCap.Flat instead of LineCap.NoAnchor: