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

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

问题描述

希望任何人都可以阐明这个角度,所以我可以用钢笔用破折号模式?

我写一个滚动的图表(A 面板的ScrollViewer 实现 IScrollInfo )在WPF中使用 DrawingVisual DataContext.Draw X 的。我有几千个 DrawingVisual s表示获得面板上滚动使用 TranslateTransform 承载它们。我通过把面板在它的上面,并绘制简单的水平线从一个边缘到另一个使用 DataContext.DrawLine(笔,新实施的网格点(0,Y),新点(widthOfPanel,Y)); //(注:这些行总是静态的,他们从来不动)。

滚动性能是绝对疯狂(即DrawingVisual的会立即绘制和滚动是即时的)。但是,如果我用使用破折号模式(参见下面的例子)提请网格线,然后滚动很生涩的表现似乎已经减少了一100(估计值)的因素。任何人都可以解释为什么会发生,我怎么能解决这个?

笔与虚线图案示例:

 <笔X:关键=PenUsingDashPatterns刷=黑厚度=1>
   < Pen.DashStyle>
      < D​​ashStyle破折号=3,3/>
   < /Pen.DashStyle>
< /笔>
 

解决方案

是笔渐冻?冻结图形对象有助于性能提升不少。

您可以建立一个加载的处理程序和调试,看看您的笔被冻结。如果没有,请手动呼吁他们的Pen.Freeze()按钮。

请注意,冻结也使笔只读...你将无法修改它们后,冻结他们。

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

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).

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.

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天全站免登陆