I try to use pixel shader effect animation programmatically in WPF, but below code uses a lot of CPU power.
Is there other method?
■Call Method Setting effect while doing sequence.
private void Button_Click(object sender, RoutedEventArgs e)
{
string path = System.IO.Path.GetFullPath(@"WateryEffect.ps");
var uri = new Uri(path);
WpfEffect wpfeffect = new WpfEffect(uri);
BitmapImage img1 = new BitmapImage(new Uri(System.IO.Path.GetFullPath(@"3a28168e68.jpg")));
ImageBrush imgbrush1 = new ImageBrush(img1);
wpfeffect.input1 = imgbrush1;
VisualBrush vbrush = new VisualBrush(text1);
wpfeffect.input1 = vbrush;
BitmapImage img2 = new BitmapImage(new Uri(System.IO.Path.GetFullPath(@"e98f58fa-2e58-4d38-9949-f3f40b6a2b13_7.jpg")));
ImageBrush imgbrush2 = new ImageBrush(img2);
wpfeffect.input2 = imgbrush2;
double i = 1;
do
{
wpfeffect.para0 = i;
image1.Effect = wpfeffect;
image2.Effect = wpfeffect;
image3.Effect = wpfeffect;
image4.Effect = wpfeffect;
DoEvents();
i = i - 0.0001;
} while (i > -1);
}
Doing a loop for this goes against the whole advantage of WPF. You need to run this effect update as a DoubleAnimation. I don't have your .ps file but I'm assuming that para01 is a DependencyProperty.
Try this code:
DoubleAnimation da =
new DoubleAnimation(0.0, 1.0, new Duration(new TimeSpan(0,0,1)); // adjust as needed
(image1.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image2.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image3.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image4.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With