How to draw line of ten thousands of points with WPF within 0.5 second?

℡╲_俬逩灬. 提交于 2019-11-29 19:59:26

Charles Petzold does exactly that. It is even faster on my host (< 0.3 secs), and the point's are even DataBound!! ;)

Tamir Khason does this also, with lines and goes into more depth about Bitmap style performance WPF here.

Rico Mariani has some guidance for 3D high performance graphics, essentially leveraging value types can improve your throughput if well thought out.

Jianzhong Zhang gives my new favourate tutorials on this subject, 3D scatter plot several tens of thousands of data points animated and interactive.

I guess the code sample is 1) a test to try a something that isn't really the sample or 2) a homework.

Try to override the OnRender and do something like:

Pen drawingPen = new Pen(Brushes.Black, 1);

protected override void OnRender(DrawingContext dc)
{
    dc.DrawRectangle(Background, null, new Rect(RenderSize));


            double x=rand.Next(300);
            double y = rand.Next(300);
            for (double i = 0; i < 1000; i = i + 0.1)
            {
                y = 100 + rand.Next(100);
                dc.DrawLine(drawingPen, new Point(i, x), new Point(i + 1, y));
                x = y;
            }


}

or for something with real data, consider if you really need to show every point depending on the resolution of the visual context. ( If your scale is 0-10 and you are producing points 0.0001,0.00015 are they really gone differ on your scale)

Arsen Mkrtchyan

Should the lines be selectable? You can draw lines in the image, then give it as a source to Image control. It will draw faster but you will lose ability to interact with lines.

Marcom

Have you considered XNA? Using a graphics card will speed up things.

Monogame, based on XNA, is alive. You can use its power to solve some special tasks requiring huge graphics performance and even inject its windows in WPF GUI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!