为什么在 WPF 自定义 2D 绘图中使用带有虚线图案的笔会导致巨大的(!)性能下降? [英] Why does use of pens with dash patterns cause huge (!) performance degredation in WPF custom 2D drawing?

查看:22
本文介绍了为什么在 WPF 自定义 2D 绘图中使用带有虚线图案的笔会导致巨大的(!)性能下降?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望任何人都可以对此有所了解,以便我可以使用带有破折号图案的笔?

Hope anyone can shed light on this so I can use pens with dash patterns?

我正在使用 DrawingVisual 在 WPF 中编写一个可滚动图表(ScrollViewer 中的一个 Panel,它实现了 IScrollInfo)的 DataContext.DrawX.我有几千个 DrawingVisual 可以通过在承载它们的 Panel 上使用 TranslateTransform 来滚动.我通过在它上面放置一个 Panel 并使用 DataContext.DrawLine(pen, new Point(0, y), new Point 从一个边缘到另一个边缘绘制简单的水平线来实现一个网格(widthOfPanel, y));//(注意:这些线总是静态的,它们从不移动).

I am writing a scrollable chart (a Panel inside ScrollViewer that implements IScrollInfo) in WPF using DrawingVisual's DataContext.DrawX. I have several thousand DrawingVisuals that get scrolled by using TranslateTransform on the Panel that hosts them. I implemented a grid by placing a Panel on top of it and drawing simple horizontal lines from one edge to the other using DataContext.DrawLine(pen, new Point(0, y), new Point(widthOfPanel, y)); //(note: these lines are always static, they never move).

滚动性能绝对是疯狂的(即,DrawingVisual 是即时绘制的,滚动是即时的).但是,如果我使用使用破折号图案的 Pen 绘制网格线(例如见下文),则滚动非常生涩,性能似乎降低了 100 倍(估计).谁能解释为什么会发生这种情况以及我如何解决这个问题?

The scroll performance is absolutely insane (i.e. DrawingVisual's are drawn instantly and scrolling is instant). But if I use a Pen that uses dash patterns (see below for example) to draw the grid lines, then scrolling is very jerky and the performance seems to have been decreased by a factor of 100 (an estimate). Can anyone explain why that happens and how I can workaround this?

带有破折号图案的笔示例:

Example of Pen with dash pattern:

<Pen x:Key="PenUsingDashPatterns" Brush="Black" Thickness="1">
   <Pen.DashStyle >
      <DashStyle Dashes="3, 3" />
   </Pen.DashStyle>
</Pen>

推荐答案

笔是否被冻结?冻结绘图对象对性能有很大帮助.

Are the pens getting frozen? Freezing drawing objects helps performance a lot.

您可以设置一个 Loaded 处理程序并进行调试以查看您的笔是否被冻结.如果没有,请手动调用 Pen.Freeze() 按钮.

You could set up a Loaded handler and debug to see if your pens are frozen. If not, Call the Pen.Freeze() button manually on them.

请注意,冻结还会使笔成为只读......冻结后您将无法修改它们.

Note that freeze also makes the pens read-only... you will be unable to modify them after you freeze them.

这篇关于为什么在 WPF 自定义 2D 绘图中使用带有虚线图案的笔会导致巨大的(!)性能下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆