WPF PathGeometry/RotateTransform 优化

发布于 2024-07-19 03:07:26 字数 1539 浏览 9 评论 0原文

我在渲染/旋转 WPF 三角形时遇到性能问题

如果我显示了一个 WPF 三角形,并且它将围绕中心点旋转到一定程度,我可以通过以下两种方式之一执行此操作:

  1. 以编程方式确定点及其偏移量在后端,使用 XAML 将它们简单地放置在它们所属的画布上,它看起来像这样:

    <路径描边=“黑色”> 
         <路径.数据> 
            <路径几何> 
                
                   
                   
                   
                
             
          
       
      
  2. 每次生成“相同”三角形,然后使用 RenderTransform(旋转)将其放置在其所属的位置。 在这种情况下,旋转计算被混淆了,因为我无权了解它们是如何完成的。

    <路径描边=“黑色”> 
         <路径.数据> 
            <路径几何> 
                
                   
                   
                   
                
             
          
         <路径.RenderTransform> 
             
          
       
      

我的问题是哪一个更快?

我知道我应该自己测试它,但是如何测量具有如此粒度的对象的渲染时间。 我需要能够计算出表单的实际渲染时间有多长,但由于我不是启动重绘的人,所以我不知道如何捕获开始时间。

I am having performance issues when rendering/rotating WPF triangles

If I had a WPF triangle being displayed and it will be rotated to some degree around a centrepoint, I can do it one of two ways:

  1. Programatically determine the points and their offset in the backend, use XAML to simply place them on the canvas where they belong, it would look like this:

    <Path Stroke="Black">
       <Path.Data>
          <PathGeometry>
             <PathFigure StartPoint ="{Binding CalculatedPointA, Mode=OneWay}">
                <LineSegment Point="{Binding CalculatedPointB, Mode=OneWay}" />
                <LineSegment Point="{Binding CalculatedPointC, Mode=OneWay}" />
                <LineSegment Point="{Binding CalculatedPointA, Mode=OneWay}" />
             </PathFigure>
          </PathGeometry>
       </Path.Data>
    </Path>
    
  2. Generate the 'same' triangle every time, and then use a RenderTransform (Rotate) to put it where it belongs. In this case, the rotation calculations are being obfuscated, because I don't have any access to how they are being done.

    <Path Stroke="Black">
       <Path.Data>
          <PathGeometry>
             <PathFigure StartPoint ="{Binding TriPointA, Mode=OneWay}">
                <LineSegment Point="{Binding TriPointB, Mode=OneWay}" />
                <LineSegment Point="{Binding TriPointC, Mode=OneWay}" />
                <LineSegment Point="{Binding TriPointA, Mode=OneWay}" />
             </PathFigure>
          </PathGeometry>
       </Path.Data>
       <Path.RenderTransform>
          <RotateTransform CenterX="{Binding Centre.X, Mode=OneWay}" 
                           CenterY="{Binding Centre.Y, Mode=OneWay}"
                           Angle="{Binding Orientation, Mode=OneWay}" />
       </Path.RenderTransform>
    </Path>
    

My question is which one is faster?

I know I should test it myself but how do I measure the render time of objects with such granularity. I would need to be able to time how long the actual rendering time is for the form, but since I'm not the one that's kicking off the redraw, I don't know how to capture the start time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦断已成空 2024-07-26 03:07:26

Have you tried using either the Perforator or the Visual Profiler included in the WPF performance tools? From the documentation it looks like these tools should be able to get you the information you're looking for. You'd have to build your application the first way, test it with these tools, take note of the performance information, and then do it all over again with the application built the second way to compare.

贪恋 2024-07-26 03:07:26

您可以像这样覆盖表单的 OnPaint 方法(伪代码):

private void OnPaint(...)
{
    // Start timer

    base.OnPaint(...);

    // Stop timer
 }

还是我太天真了?

You could override the form's OnPaint method like this (pseudo code):

private void OnPaint(...)
{
    // Start timer

    base.OnPaint(...);

    // Stop timer
 }

or am I being incredibly naive?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文