简体   繁体   中英

low frame rate wpf on path scale animation (huge path data)

can anyone tell me how can I animate a Path object with the huge amount of Data in WPF?

here is a very simple code:

<Window x:Class="WpfApp3.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp3"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800" MouseWheel="MainWindow_OnMouseWheel">
<Grid>
    <Path   StrokeThickness="1" Stroke="#FF000000" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" 
                     StrokeEndLineCap="Flat">
        <Path.RenderTransform>
            <ScaleTransform x:Name="ScaleTransform"></ScaleTransform>
        </Path.RenderTransform>
        <Path.Data>
            <PathGeometry Figures="%%Data%%" FillRule="NonZero"/>
        </Path.Data>
    </Path>
</Grid>

using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace WpfApp3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window 
    {
    private double _scale = 1;
    public MainWindow()
    {
        InitializeComponent();
    }

    private void MainWindow_OnMouseWheel(object sender, MouseWheelEventArgs e)
    {
        if (e.Delta > 0)
            _scale *= 2;
        else
            _scale /= 2;

        DoubleAnimation a = new DoubleAnimation(_scale, TimeSpan.FromMilliseconds(2000));
        ScaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, a);
        ScaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, a);
    }

    }
}

Note as you monitor resolution is increased the frame rate gets decreased.

PathData:

M 9.9390855 -9.3573639 H 499.29287 v 6.431173 H 9.3544333 V 7.0128956 H 496.95427 V 17.536631 H 8.1851293 v 9.354434 H 496.36962 v 9.939086 H 8.1851293 L 11.158048 47.925233 H 492.27705 V 63.724147 H 9.3544333 L 13.731642 80.060112 H 494.031 l -7.15238 26.693068 H 173.64167 50.864732 8.1851293 v 24.79061 H 493.44635 v 18.70887 H 9.3544333 v 13.44699 H 492.8617 v 19.29352 H 10.523738 v 19.87817 H 495.20033 v 22.80143 H 13.446998 v 15.20096 H 489.3538 l 7.64244 28.52201 H 14.03165 v 22.34271 H 491.6924 V -17.542493 H 471.81423 V 291.73845 H 454.27468 V -18.127145 H 402.24064 V 288.81521 h 32.74052 V -14.03458 h -64.31174 v 296.41861 l -27.49889 7.3683 V -15.203885 h -27.4584 V 282.96868 h -29.2326 V -17.542493 H 247.89248 V 281.21473 c 0 0 -24.69105 2.26028 -23.38608 0 1.30497 -2.26028 0 -298.172571 0 -298.172571 H 196.4431 V 284.72263 c 0 0 -34.49447 5.84652 -34.49447 0 0 -5.84652 0 -298.172558 0 -298.172558 H 135.63928 V 278.87611 H 98.806202 V -14.619233 H 67.23499 V 273.61426 H 34.494472 V -16.373189 H 7.6004771 V 287.06126 H 73.666164 V -17.542493 H 129.20811 V 285.89193 h 91.79038 V -13.449928 l 17.93326 4.8052031 V 287.64591 h 25.91563 V -15.788537 h 32.15587 V 286.47658 c 0 0 23.52175 10.40344 26.30935 0 2.7876 -10.40342 0 -301.095813 0 -301.095813 0 0 33.32517 -1.169304 33.32517 0 0 1.169305 0 297.003263 0 297.003263 H 330.32842 V -17.542493 h 59.63452 V 276.53751 l 30.22632 8.0991 V -12.865276 H 173.05702 V 278.29146 H 107.57598 V -17.542493 H 38.587037 V 268.35238 c 0 0 23.612633 4.88559 23.612633 -6.32698 0 -11.21259 0 -276.05998 0 -276.05998 L 47.847212 39.529523 V 265.42911 H 477.66075 L -2.4598142 -11.768623 V 290.56915 L 477.8195 13.279769 H 150.84024 L 78.982265 137.74143 293.1374 195.12412 463.57801 96.720196 275.20902 46.246883 60.907501 103.66881 259.88424 218.54808 379.24356 250.53032 467.02646 98.485851 362.00307 -6. 5375409 H 193.51984 L 96.365667 19.494842 13.741784 162.6036 70.853667 219.71549 279.0081 163.94068 222.61914 66.27214 105.10566 34.784496 H 345.52937 L 452.84204 6.0301564 V 199.94808 L 154.0296 280.01463 83.996002 158.71288 431.78722 65.522512 358.88255 23.43099 H 150.84024 L 58.048389 184.15119 462.11722 292.42111 V 129.20518 4.089634 H 311.0349 83.020597 L 232.69153 153.76057 401.59207 108.50381 457.63134 52.464523 H 244.96922 L 342.31254 221.06811 43.032539 140.87627 247.93747 22.574356 419.91475 194.55165 125.92783 273.3252 191.99353 26.764676 V 265.42911 c 0 0 16.84109 -0.94165 16.84109 -16.84107 0 -15.89944 0 -250.9295788 0 -250.9295788 H 480.584 V 283.55333 l 1.75398 0.58465 -94.71364 1.16931 L 384.11643 22.798501 279.4637 14.613372 267.77066 96.464665 266.60135 294.07707 242.63062 243.79699 c -34.49447 -5.26187 -141.48581 9.35444 -141.48581 9.35444 -16.954909 -33.90983 84.1899 -166.041198 84.1899 -166.041198 4. 67722 -1.753957 150.25559 -4.677217 150.25559 -4.677217 30.98656 12.277694 40.92565 23.970735 40.92565 23.970735 10.52374 25.14004 30.98656 43.84891 30.98656 43.84891 -5.84652 30.98656 -46.18752 63.72708 -46.18752 63.72708 -35.07912 2.3386 -58.46521 -7.01583 -58.46521 -7.01583 C 206.96684 171.88479 185.91937 140.31357 185.91937 140.31357 146.16302 115.75818 137.97789 78.925102 137.97789 78.925102 116.34577 70.739973 84.774553 9.3515033 84.774553 9.3515033 121.02298 8.7668512 317.46609 -4.0954948 317.46609 -4.0954948 c 23.97073 0 92.95968 26.3093438 92.95968 26.3093438 15.20095 30.986561 44.43356 116.930421 44.43356 116.930421 19.87817 44.43356 36.83308 80.09733 36.83308 80.09733 -2.33861 23.97074 -21.04748 18.12422 -21.04748 18.12422 -46.18751 -31.57121 -47.35681 -31.57121 -47.35681 -31.57121 -18.70887 -0.58466 -102.31412 14.6163 -102.31412 14.6163 -86.52851 13.447 -121.60764 18.12421 -121.60764 18.12421 -97.6369 26.3093 5 -127.454153 32.74052 -127.454153 32.74052 -50.28008 12.86235 -53.20334 -28.0633 -53.20334 -28.0633 C 32.740517 161.36105 35.079126 90.033492 35.079126 90.033492 35.663778 61.970192 57.880557 11.10546 57.880557 11.10546 c 88.282463 11.108389 181.826803 9.939085 181.826803 9.939085 119.26903 5.261869 188.84262 4.677217 188.84262 4.677217 41.5103 32.740517 45.01822 67.234991 45.01822 67.234991 -1.75396 39.171687 -7.01583 87.113157 -7.01583 87.113157 18.12422 57.29591 9.93909 71.32756 9.93909 71.32756 -12.86235 17.53956 -56.71126 -19.29352 -56.71126 -19.29352 -35.07912 -13.447 -0.58465 26.894 -0.58465 26.894 25.14004 3.50791 32.15587 1.75395 32.15587 1.75395 -172.47237 2.92326 -214.56732 -4.09256 -214.56732 -4.09256 -64.31173 -0.58465 -95.88295 1.1693 -95.88295 1.1693 -11.10839 0 -41.510294 -50.28008 -41.510294 -50.28008 -5.261869 -9.35443 -27.697617 -27.9398 -17.592033 -65.65436 10.105584 -37.71455 -14.350212 -87.205924 0 -101.556136 14.350211 -14.350211 119.679597 27.472271 167.262967 0 47.58337 -27.472271 137.87135 -76.946396 157.87329 -42.3020193 20.00194 34.6443763 47.09868 81.5773183 60.38059 104.5822553 13.28191 23.00493 12.60158 -5.024275 12.60158 47.02973 0 52.05401 36.25673 49.24539 0 70.17823 -36.25673 20.93283 -13.08656 44.73405 -57.06922 32.94893 -43.98267 -11.78512 -13.71718 -3.67551 -86.55171 -23.19146 C 263.4618 210.06778 202.69037 126.37021 180.10782 139.40825 157.52526 152.4463 128.18851 144.7373 101.90511 118.4539 75.621716 92.170504 61.794056 88.122064 48.435394 64.984182 35.076731 41.8463 37.549954 -3.2144908 16.571855 33.120643 c -20.9780995 36.335134 -5.942827 73.905607 0 96.084537 5.942827 22.17894 21.08962 71.28007 51.185539 88.65596 30.095919 17.37588 27.962231 7.49245 121.835796 32.6458 93.87356 25.15335 70.4376 48.08086 118.51846 0 48.08086 -48.08086 64.06367 -27.06589 77.60579 -77.60579 13.54213 -50.5399 60.03 367 -31.78779 33.60899 -58.21247 C 392.90175 88.263995 446.09705 89.463785 375.06986 70.432107 304.04267 51.400428 355.90942 19.101598 269.70561 42.19984 183.50179 65.298082 170.5094 68.779383 118.03276 82.840457 65.556116 96.901531 15.084417 121.14966 75.7073 156.1503 c 60.62288 35.00064 -2.946233 49.53018 85.78878 49.53018 88.73502 0 89.48031 -11.7355 129.04282 -34.57692 39.5625 -22.84142 72.95695 -5.9875 48.44443 -48.44443 C 314.47081 80.202196 342.81589 65.909136 299.52096 54.308294 256.22603 42.707452 315.14921 58.49587 230.49928 35.81399 145.84935 13.132109 174.03821 8.8045591 129.69871 8.8045591 c -44.339504 0 -21.79089 -65.3841661 -59.540459 0 C 32.408686 74.188725 29.051489 77.030339 40.464349 119.62371 c 11.41286 42.59337 30.325961 75.88639 25.329829 94.53221 -4.996132 18.64582 -14 .518831 1.73318 5.948649 22.20066 20.46748 20.46748 -0.02999 57.09475 45.022873 45.02287 45.05285 -12.07188 -37.501136 10.0484 69.86346 -18.71986 107.3646 -28.76826 128.21788 -59.14237 174.4701 -46.74912 46.25221 12.39324 39.35448 9.09494 73.29725 0 33.94276 -9.09494 58.21059 32.13185 46.91741 12.57148 -11.29318 -19.56036 -39.63475 -68.6494 -43.7245 -75.73306 -4.08975 -7.08365 1.37549 5.1334 -2.88423 -10.76407 -4.25971 -15.89748 -9.83489 -19.11876 -9.83489 -36.70435 0 -17.585586 1.55223 -27.301202 12.30633 -45.92785 10.7541 -18.626648 4.84324 -13.82776 12.27307 -21.257582 7.42982 -7.429823 3.92191 -3.921911 16.78425 -16.784257 12.86235 -12.8623458 15.78561 -15.7856063 15.78561 -15.7856063 0 0 0 -9.6206695 0 33.6435853 0 43.264255 -12.40115 19.199304 0 65.48103 12.40115 46.28173 30.9696 70.08695 24.87467 92.83353 -6.09493 22.74658 2.83531 22.73327 -16.04601 27.79251 -18.88133 5.05923 -23.21656 6.22085 -43.29261 11.60022 -20.07605 5.37936 -36.51643 23.96586 -89.44183 23.96586 -52.92539 0 -30.12396 0 -84.4966 0 -54.37265 0 -38.00239 0 -65.48103 0 -27.47865 0 -27.62124 7.48133 -55.54195 0 -27.92071 -7.48133 -27.61583 19.78821 -46.18547 -12.37536 C 87.83909 216.30299 88.238415 216.99464 68.439326 182.70161 48.640237 148.40858 28.172949 81.17404 37.09456 65.721355 46.016172 50.268671 26.814074 25.974127 76.841789 25.974127 c 50.027711 0 103.103691 11.626748 146.495311 0 43.39161 -11.626749 -6.70527 -20.9553236 78.20633 -20.9553236 84.9116 0 100.8597 -9.0200128 116.48282 0 15.62312 9.0200126 26.39195 -9.3966421 18.82893 18.8289346 -7.56302 28.225577 1.45495 19.115508 -28.09977 48.670224 -29.55471 29.554718 -18.21013 20.385838 -50.11762 28.935428 -31.90749 8.54958 -38.38517 -16.255704 -99.05226 0 -60.6671 16.25569 -17.06748 17.56067 -65.53732 17.56067 -48.46984 0 -76.19493 -16.36816 -86.81371 23.26166 -10.618775 39.62982 -5.0521 67.04608 0 75.79658 5.0521 8.7505 21.6657 33.86317 58.65274 33.86317 36.98704 0 4 .3563 46.51839 84.92851 0 80.57221 -46.51839 103.10463 -58.37041 105.8423 -61.10808 2.73767 -2.73767 7.63331 9.54532 0 -18.9426 -7.63332 -28.48793 -9.35861 -21.32745 -9.35861 -34.92679 0 -13.59934 33.30907 -74.987808 32.72442 -84.342242 -0.58465 -9.354433 0 -60.2191654 0 -60.2191654 l -213.98267 0 L 126.14562 141.28891 240.90403 256.04732 317.99906 122.51481 153.36913 78.402353 57.421997 174.34949 v 75.87868 L 445.12315 146.34395 387.63386 88.854664 c 0 0 21.97223 53.118276 15.86849 59.222006 -6.10374 6.10374 20.21042 75.4263 20.21042 75.4263 l 10.63962 -39.7076 28.88369 -107.795407 0 191.183117 H 320.974 L 220.07693 294.21837 113.76901 265.73325 -0.56346214 151.40077 24.8056 56.722143 277.58826 -11.010767 417.50185 69.768377 H 316.29678 c 0 0 -77.44671 -32.177162 -83.1594 -22.282494 -5.71269 9.894669 -98.61277 26.423213 -98.61277 26.423213 l 67.07551 116.178184 98.52716 98.52716 116.14501 -116.145 V 58.462279 L 252.6126 4 14.609807 H 53.787993 L 13.172334 -8.8396548 h 98.496216 c 0 0 56.92242 14.8299816 58.28743 15.6180695 1.36501 0.7880879 -42.18954 116.2964253 -32.63901 121.8104353 9.55053 5.514 112.30718 112.30718 112.30718 112.30718 0 0 109.48988 -3.81219 111.69084 0 2.20097 3.81218 -49.65298 -130.70639 -36.98276 -138.02154 12.67022 -7.315159 -95.74175 -55.276532 -95.74175 -55.276532 0 0 -176.594294 -0.947088 -177.141096 0 -0.546802 0.947088 0 172.812952 0 172.812952 0 0 5.903862 80.58267 0 77.17408 -5.903861 -3.4086 3.351256 -0.89797 59.878486 -16.0444 56.52723 -15.14642 281.7518 -162.66947 281.7518 -162.66947 0 0 69.64502 -46.127829 71.01835 -41.00247 1.37334 5.125359 -40.62396 151.61071 -40.62396 151.61071 0 0 -28.28437 44.89857 -27.5356 47.69304 0.74878 2.79448 -46.90116 0 -52.16303 0 -5.26187 0 -107.82333 -186.755491 -107.82333 -186.755491 L 151.69416 6.1589742 319.48415 51.118165 V 156.68383 l -24.17938 90.23867 c 0 0 22.61126 171.0644 -11.61266 43.33902 -34.22391 -127.72538 0 -251.677412 0 -251.677412 l 54.14483 31.260533 c 0 0 26.52255 123.850339 32.29292 120.518819 5.77037 -3.33153 -236.79697 -55.75703 -242.05107 -64.85739 C 122.8247 116.40571 42.210544 39.637819 42.210544 39.637819 L 20.368151 1.8056849 c 0 0 4.037415 108.7134451 0 115.7064551 -4.037414 6.99301 2.785273 127.61582 0 126.8695 -2.785272 -0.74631 291.836069 0 291.836069 0 0 0 113.09383 -78.6833 105.82203 -105.82202 -7.2718 -27.13873 0 -101.144816 0 -101.144816 l 61.8367 -35.7014353 c 0 0 3.4397 163.2238013 0 166.6635013 -3.43971 3.4397 3.43797 92.71158 0 91.79038 -3.43797 -0.9212 -109.9592 -28.24607 -111.62221 -29.90908 -1.663 -1.663 48.4343 -62.26457 62.26458 -62.26457 13.83027 0 64.102 -25.23927 39.46401 -39.46402 -24.63799 -14.22475 -10.13639 -52.857128 -91.55123 -52.857128 -81.41484 0 -83.94149 14.675378 -1 38.71074 0 C 184.9381 60.997074 170.39578 44.147238 155.07194 52.99446 139.7481 61.841683 255.49296 180.06991 255.49296 180.06991

The StreamGeometry object is a lightweight alternative to PathGeometry for creating geometric shapes. Use a StreamGeometry when you need to describe a complex geometry. StreamGeometry is optimized for handling many PathGeometry objects and performs better when compared to using many individual PathGeometry objects.

The following example uses attribute syntax to create a triangular StreamGeometry in XAML.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>

    <Path Data="F0 M10,100 L100,100 100,50Z" 
      StrokeThickness="1" Stroke="Black"/>

  </StackPanel>
</Page>

For more information on StreamGeometry objects, see Create a Shape Using a StreamGeometry .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM