I did not try your animation approach, I tried to implement my own logic for this.
At first I was inspired by the scaling animations used by Picasa . So I tried to implement this type of animation, and it works fine for me on my core2duo processor with an image size of 10000x5000 without any lag. This approach consumed a lot of memory, but when I compared my memory usage with Picasa ImageViewer , it was almost the same. This approach may increase the load time of your application, but it can be handled, not a problem.
Here is the code for the main window that I used.
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button Grid.Row="0" Height="30" Width="100" Content="Zoom" Click="ButtonZoom_OnClick" /> <Image RenderOptions.BitmapScalingMode="HighQuality" Stretch="Uniform" Width="100" Height="100" Grid.Row="1" Margin="30" VerticalAlignment="Center" HorizontalAlignment="Center" Source="mad1.jpg" Name="ImageMain" x:FieldModifier="private" /> </Grid>
Copy Event Code Button
private void ButtonZoom_OnClick(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { var i = 0; while (i++ < 100) { var i1 = i; //var i1 = (-0.00092)*(i*i) + (0.092)*i + 0.2; Dispatcher.Invoke(new Action(() => { if (i1 < 10 || i1 > 90) { ImageMain.Height += 0.5; ImageMain.Width += 0.5; } else if (i1 < 30 || i1 > 70) { ImageMain.Height += 1; ImageMain.Width += 1; } else { ImageMain.Height += 3; ImageMain.Width += 3; } })); Thread.Sleep(30); } }); }
The commented line in this code is a quadratic equation for smooth animation to speed up and speed up the animation. roots are calculated to start scaling at 0.2 and half at 2.5 and stop at 0.2 with a range of [0-100]. if you want to create a fully customized animation, you can use WolframAlpha to check the animation schedule. but a simple approach is to use simple control statements to control your animation.
This code is only for scaling an image, your approach will be similar for zooming out.
source share