WPF中的折线图优化. [英] Polyline drawing optimization in WPF.

查看:483
本文介绍了WPF中的折线图优化.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在研究wpf图表绘制,并且已经能够生成虚拟范围图.

我正在使用以下方法:

Hello everyone.

I am studying the wpf chart drawing and I have been abled to generate a dummy scope graph.

I am using the following method:

public Polyline NormalizedValues(Polyline pl)
{
  Polyline result = new Polyline();

  for (int i = 0; i < pl.Points.Count; i++)
  {
    Point pt = pl.Points[i];
    Point npt = NormalizedValue(pt);

    result.Points.Add(npt);
  }

  return result;
}

public Point NormalizedValue(Point pt)
{
  Point npt = new Point();

  npt.X = (pt.X - _ca.xMin) * chartCanvas.Width / (_ca.xMax - _ca.xMin);
  npt.Y = chartCanvas.Height -
           (pt.Y - _ca.yMin) * chartCanvas.Height / (_ca.yMax - _ca.yMin);

  return npt;
}

public void Draw()
{
  // Clean the chart area.
  chartCanvas.Children.Clear();

  foreach (Trace tr in _Traces)
  {
     Polyline Normalized = NormalizedValues(tr.Values);
     Normalized.Stroke = tr.Color;
     chartCanvas.Children.Add(Normalized);
  }
}



如果chartCanvas的大小为300 x 300左右,则绘制速度非常快,但是一旦窗口最大化,曲线绘制就会开始变慢.

我想请教您有关我可以用来优化图纸的不同技术的建议.

我发现以下文章:
http://www.newyyz.com/ntgsite/2012/02/fast -line-rendering-in-wpf/

但这似乎与GDI有关,而与WPF渲染不直接相关.

我们喜欢GDI,位图渲染还是双缓冲方法?
有人可以给我一些wpf优化的有用链接吗?
如果没有我粘贴的代码的稳定性,什么是最好的方法?

如何有效地绘制封装在Polyline对象中的至少1024个样本的序列?速度非常快,但前提是我的画布大约为200 *200.

欢迎任何输入?我真的会了解什么是最适合解决我的问题的解决方案.

提前非常感谢您.
最好的问候.
MiQi.



If the size of the chartCanvas is around 300 x 300, the drawing is very fast but once the window is maximized then the curve drawing starts to be much slower.

I would like to ask your advise about the different possible technique I could apply to optimize the drawing.

I have found the following article:
http://www.newyyz.com/ntgsite/2012/02/fast-line-rendering-in-wpf/

But it seems to be related to GDI and not on WPF rendering directly.

Do we have like in GDI, bitmap rendering or double buffering methods ?
Could somebody provide me some usefull links to wpf optimization ?
What could be the best approach without based on the peace of code I have pasted?

How would it be possible to draw a serie of at least 1024 samples encapsulated in a Polyline object efficiently ? It is very fast but only if my canvas is around 200 * 200.

Any inputs are welcome ? I would really learn what is the best suitable solution to cover my issue.

Thank you very much in advance.
Best regards.
MiQi.

推荐答案

WPF与GDI无关,与Windows无关.这看起来似乎是Windows迈出的一大步,而Windows是一个具有巨大跨平台潜力的库.如果您还记得Microsoft在非Windows操作系统(称为"Midory")上工作,这是非常可解释的.我真的希望方向工作不会停止.

在结构上最接近GDI的方法是在应用程序代码中进行渲染.

我不能保证会提高性能,但仍然建议您尝试一种完全不同的方法.使用System.Windows.Controls.Canvas的实例托管充当图节点,弧等角色的UI元素.请参见:
http://msdn.microsoft.com/en-us/library/system. windows.controls.canvas.aspx [ ^ ].

另请参阅我过去有关相关主题的答案:
连接不同的控件 [矢量图形软件,例如C#或VB.NET中的CorelDraw或Inkscape [ ^ ].

我真的建议尝试一下. WPF的构建考虑到了高性能,而您正在考虑在应用程序级别上进行的优化已在WPF的更高级别上得到了考虑.也解决了闪烁问题.



这是一个非常简单的Canvas教程,但由于它仅仅是静态XAML,所以并没有太大帮助,但是您确实需要阅读" C#编程:
http://wpftutorial.net/Canvas.html [ http://msdn.microsoft.com/en-us/library/ms749011.aspx [ ^ ].

另请参见:
http://www.wpftutorial.net/DependencyProperties.html [ http://msdn.microsoft.com/en-us/library/ms754152.aspx [ ^ ].

有关相关概述和介绍性材料,请从此处开始:
http://msdn.microsoft.com/en-us/library/ms745058.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms742562.aspx [ ^ ].

有关更多概述,请从这里开始:
http://msdn.microsoft.com/en-us/library/ms754130.aspx [ ^ ].

—SA
Well, WPF has nothing to do with GDI and very, very little to do with Windows. It looks like a big step out of Windows, a library with great cross-platform potential. This is very explainable if you remember that Microsoft is working on a non-Windows OS, called "Midory". I really hope the work in direction won''t stop.

What you do it the approach structurally closest to GDI, where you do rendering in the application code.

I cannot promise performance improvements, but still advise you to try a completely different method. Use the instance of System.Windows.Controls.Canvas to host the UI elements playing the role of the graph nodes, arcs, etc. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[^].

Please also see my past answers on related topics:
Connect different controls[^],
Vector graphics software like CorelDraw or Inkscape in C# or VB.NET[^].

I really recommend trying it. WPF is build with high performance in mind, and the optimization you are thinking about on the application level is already thought at higher level of WPF. Тhe problem of flicker is solved as well.



This is ridiculously simple Canvas tutorial, but it would not help much as this is mere static XAML, but you really need "read" C# programming:
http://wpftutorial.net/Canvas.html[^].

You really need to add elements programmatically and move them using SetLeft, SetTop, etc. This is related to attached properties, but using them does not require you to understand how they work, because you can use the methods like those I''ve shown above; but they implement attached properties of the children, which you don''t have to use. If you really need to understand attached properties (highly recommended for general WPF understanding), please see:
http://msdn.microsoft.com/en-us/library/ms749011.aspx[^].

See also:
http://www.wpftutorial.net/DependencyProperties.html[^].

For understanding of aspects of Canvas as a parent control, see this overview:
http://msdn.microsoft.com/en-us/library/ms754152.aspx[^].

For related overview and introductory material, start here:
http://msdn.microsoft.com/en-us/library/ms745058.aspx[^],
http://msdn.microsoft.com/en-us/library/ms742562.aspx[^].

For more overviews, please start here:
http://msdn.microsoft.com/en-us/library/ms754130.aspx[^].

—SA


这篇关于WPF中的折线图优化.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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