Use StreamGeometry in WPF to improve performance ., Wpfstreamgeometry

Source: Internet
Author: User

Use StreamGeometry in WPF to improve performance ., Wpfstreamgeometry

We are currently using WPF to develop a stock K-line chart. performance considerations are the biggest aspect. Each column is 5 pixels wide, and the interval between the column and the column is 3 pixels.

A 1920*1080 resolution screen is bound to draw more than 200 columns. If the selected drawing scheme is not advanced, it will have a great impact on the performance of the chart.

Any graph consists of a straight line and a curve. In WPF, the lowest level of drawing is Geometry.

In WPF, The DrawingContext method is used to draw a straight line. A LineGeometry object is created internally and a rectangle is drawn. A RectagleGeometry object is created internally.

Therefore, it is unscientific to use the traditional DrawLine and DrawRectangle to draw these columns. Because each column contains a rectangle and a straight line.

Suppose we Plot 200 columns, and instantiate 200 LineGeometry objects and 200 RectangleGeometry objects each time.

While dragging, the screen delay is very obvious when the Geometry object is instantiated and recycled constantly.

Is there a scheme to reduce the generation of objects. StreamGeometry! StreamGeometry is very efficient because it directly stores the data drawn by byte streams.

StreamGeometry works in a way similar to a laser printer. It can switch the starting coordinates of the next drawing at will.

After carefully analyzing the K-line chart, we will find that the K-line chart is composed of two colored columns. Because DrawingContext can only submit one color fill and draw edge commands at a time. Therefore, it must be drawn at least twice.

Using two StreamGeometry objects, You can first draw red columns and then draw all columns in green.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.