我似乎无法让我存储在独立存储中的图像出现在我的 Storyboard中,我可以在用相机拍照时将图像输出到屏幕上,但是当我使用相同的文件名时 Value = String.Format("MyImage{0:D2}.jpg", i)
作为我存储它们的位置,如果我在 Storyboard 中再次打开独立存储,它似乎不起作用。我用的是蜡烛动画教程here但这些图像位于静态保存的文件夹中。谁能帮忙,我将不胜感激。
编辑 我可以从独立存储中打开一个图像,但它是出现的最后一个图像,我什至不知道它是否正在运行动画,因为它只有一个图像,有人可以帮忙吗? 代码在下面的第二篇文章中
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
AnimationPanel.Visibility = Visibility.Visible;
storyboard = new Storyboard
{
RepeatBehavior = RepeatBehavior.Forever
};
var animation = new ObjectAnimationUsingKeyFrames();
Storyboard.SetTarget(animation, CandleImage);
Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));
storyboard.Children.Add(animation);
for (int i = 0; i <= savedCounter; i++)
{
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(50 * i)),
Value = String.Format("MyImage{0:D2}.jpg", i)//images from isolated storage
};
animation.KeyFrames.Add(keyframe);
}
Resources.Add("CandleStoryboard", storyboard);
storyboard.Begin();
}
}
编辑 我可以从独立存储中打开一个图像,但它是出现的最后一个图像,我什至不知道它是否正在运行动画,因为它只有一个图像,有人可以帮忙吗?谢谢
这是我使用的代码
for (int i = 0; i < savedCounter; i++)
{
try
{
image.SetSource(isStore.OpenFile("MyImage"+i+".jpg", FileMode.Open));//images from isolated storage
}
catch (Exception)
{
//throw;
}
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(50 * i)),
Value = image
};
animation.KeyFrames.Add(keyframe);
}
Resources.Add("CandleStoryboard", storyboard);
storyboard.Begin();
}
else
{
storyboard.Stop();
}
}
最佳答案
使用 IsolatedStorageFileStream 从 isolatedstorage 读取图像,然后在 Storyboard中使用它。
关于c# - 如何将存储在隔离存储中的图像用于 Storyboard 动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9923067/