为什么使用笔与划线模式导致在WPF自定义的2D绘图巨大(!)性能下降? [英] Why does use of pens with dash patterns cause huge (!) performance degredation in WPF custom 2D drawing?
问题描述
希望任何人都可以阐明这个角度,所以我可以用钢笔用破折号模式?
我写一个滚动的图表(A 面板
在的ScrollViewer
实现 IScrollInfo
)在WPF中使用 DrawingVisual
的 DataContext.Draw
的 X 的。我有几千个 DrawingVisual
s表示获得面板上滚动使用
承载它们。我通过把 TranslateTransform
面板
在它的上面,并绘制简单的水平线从一个边缘到另一个使用 DataContext.DrawLine(笔,新实施的网格点(0,Y),新点(widthOfPanel,Y));
//(注:这些行总是静态的,他们从来不动)。
滚动性能是绝对疯狂(即DrawingVisual的会立即绘制和滚动是即时的)。但是,如果我用笔
使用破折号模式(参见下面的例子)提请网格线,然后滚动很生涩的表现似乎已经减少了一100(估计值)的因素。任何人都可以解释为什么会发生,我怎么能解决这个?
笔与虚线图案示例:
<笔X:关键=PenUsingDashPatterns刷=黑厚度=1>
< Pen.DashStyle>
< DashStyle破折号=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.Draw
X. I have several thousand DrawingVisual
s 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屋!