이미지 여러장을 이용해서 애니메이션을 만드는것

참고 : http://coderelief.net/2009/05/21/frame-based-animation-in-wpf/
public partial class MainWindow : Window{public static readonly DependencyProperty FramesPerSecondProperty = DependencyProperty.Register("FramesPerSecond", typeof(double), typeof(MainWindow));private List<string> imageList = new List<string>();private TimeSpan LastRenderTime { get; set; }public double FramesPerSecond{get { return (double)GetValue(FramesPerSecondProperty); }set{if (value <= 0){throw new Exception("FramesPerSecond must be greater than 0.");}SetValue(FramesPerSecondProperty, value);}}private int index = 1;public MainWindow(){InitializeComponent();this.Loaded += MainWindow_Loaded;}private void MainWindow_Loaded(object sender, RoutedEventArgs e){for (int i = 1; i < 21; i++){imageList.Add(string.Format("/ImageSequence;component/Images/e2000{0}.png", i));}FramesPerSecond = 10;CompositionTarget.Rendering += CompositionTarget_Rendering;}private void CompositionTarget_Rendering(object sender, EventArgs e){TimeSpan timeSinceLastRender;timeSinceLastRender = (DateTime.Now.TimeOfDay - LastRenderTime);if (timeSinceLastRender.TotalSeconds < (1 / FramesPerSecond)){return;}LastRenderTime = DateTime.Now.TimeOfDay;if (index < 20){xImage.Source = new BitmapImage(new Uri(imageList[index], UriKind.RelativeOrAbsolute));index++;}else{index = 1;}}}
'wpf' 카테고리의 다른 글
ListBox에서 Item 스크롤 터치시 화면 전체가 움직이던 문제 (0) | 2016.04.25 |
---|---|
SoundPlayer 사용 (0) | 2016.04.25 |
blend 디자인모드 무시 (0) | 2016.04.21 |
Image Filter 사용하기 (이미지 프로세싱) (0) | 2016.04.19 |
WPF HtmlToXaml에 Image Add하기 (0) | 2016.04.14 |