Windows应用程序中的逐帧动画闪烁

时间:2014-01-10 07:47:13

标签: c# xaml windows-phone windows-store-apps

我想在我使用此代码的Windows应用商店应用中逐帧动画实现:

void moving_objects(DependencyObject obj_name, string img_path, int no_of_frames, int time_to_play)
{

   var animation = new ObjectAnimationUsingKeyFrames();
   framestory = new Storyboard();


   Storyboard.SetTarget(animation, obj_name);
   Storyboard.SetTargetProperty(animation, "Source");

   framestory.Children.Add(animation);

   for (int i = 1; i <= no_of_frames; i++)
   {
      // MessageBox.Show(img_path + i + ".png");
      var keyframe = new DiscreteObjectKeyFrame
      {
          KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(time_to_play * i)),
          Value = new BitmapImage(new Uri(this.BaseUri, img_path + i + ".png")),
      };

      animation.KeyFrames.Add(keyframe);

   }

   framestory.Begin();


}

我在这样的图像上调用这个方法:

moving_objects(DogImage, "/Assets/Images/Dog/d", 12, 150);

此代码在Windows手机应用程序中运行良好,但对于商店应用程序,动画闪烁,即图像需要时间加载。我可以解决这个问题吗?

0 个答案:

没有答案