DrawPath(Pen,GraphisPath) 抛出 OutOfMemoryException

发布于 2024-12-02 04:33:46 字数 528 浏览 1 评论 0原文

我已经思考过这个问题好几次了,但无法弄清楚。 DrawPath 方法抛出 System.OutOfMemoryException。

我发现 pen.DashPattern 实际上也抛出了 System.OutOfMemoryException,因此我设置了破折号模式,但纠正它并没有阻止错误。

using (var pen = new Pen(Color.Black,1.0f))
{
    pen.DashPattern = new[]{1.0f};
    pen.Transform = context.ReverseTransform;
    try
    {
        using (var temporaryPath = new GraphicsPath(path.PathPoints, path.PathTypes))
        {
            context.Graphics.DrawPath(pen, temporaryPath);
        }
    }
}

在这里任何帮助都会很可爱!提前致谢!

I've been over this for a couple of time and can't figure it out. the method DrawPath is throwing a System.OutOfMemoryException.

I've seen that the pen.DashPattern is actually throwing System.OutOfMemoryException as well, so I set the dash pattern, but correcting that didn't prevent the error.

using (var pen = new Pen(Color.Black,1.0f))
{
    pen.DashPattern = new[]{1.0f};
    pen.Transform = context.ReverseTransform;
    try
    {
        using (var temporaryPath = new GraphicsPath(path.PathPoints, path.PathTypes))
        {
            context.Graphics.DrawPath(pen, temporaryPath);
        }
    }
}

Any help in here would be lovely! thanks in advance!

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

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

发布评论

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

评论(1

冬天旳寂寞 2024-12-09 04:33:46

考虑到您正在处理 Pen 和 Path 对象的属性,这不太可能是问题的根本原因。该行可能会引发异常,但问题已经酝酿了一段时间,这只是稻草压断了骆驼的背,掀翻了冰山……你明白了。也就是说,正如 Tigran 在评论中提到的那样,了解 PathPoints 数组有多大会很有帮助。

为自己准备一个好的分析器(我使用 RedGate 的 ANTS 内存分析器 有免费试用版),让您的应用程序正常运行,让内存使用量增加,然后使用探查器结果来缩小实际罪魁祸首的范围。请回来提供更多信息或您的结果,我将很乐意为您提供进一步的帮助。

It's highly unlikely that this is the root cause of your problem considering that you are property disposing of the Pen and Path object.. That line may be throwing the exception, but the problem has already been brewing for some time and this is just the straw that broke the camel's back, tipped the iceberg... you get it. That said, it would be helpful to know how large your PathPoints array is as Tigran mentioned in a comment.

Get yourself a good profiler (I use RedGate's ANTS Memory Profiler which has a free trial), put your app through it's paces, let the memory usage build up, and then use the profiler results to narrow down the actual culprit. Come back with some more info or your results and I will be happy to help further.

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