잊지 않겠습니다.

'Image animation'에 해당되는 글 1건

  1. 2010.01.05 0006. CSWPFAnimatedImage
WPF를 이용한 Image animation

System.Windows.Media.Animation.StoryBoard controller를 이용해서 Image Animation을 할 수 있다.
Image Animation 형태는 StoryBoard Controller의 Property들을 변경시키면 가능하다.



int nextImageIndex;
List images = new List();

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    // initialize the images collection
    images.Add(new BitmapImage(new Uri("Images/image1.jpg", UriKind.Relative)));
    images.Add(new BitmapImage(new Uri("Images/image2.jpg", UriKind.Relative)));
    images.Add(new BitmapImage(new Uri("Images/image3.jpg", UriKind.Relative)));
    images.Add(new BitmapImage(new Uri("Images/image4.jpg", UriKind.Relative)));

    nextImageIndex = 2;
}
       
private void VisbleToInvisible_Completed(object sender, EventArgs e)
{
    // change the source of the myImage1 to the next image to be shown 
    // and increase the nextImageIndex
    this.myImage1.Source = images[nextImageIndex++];

    // if the nextImageIndex exceeds the top bound of the ocllection, 
    // get it to 0 so as to show the first image next time
    if (nextImageIndex == images.Count)
    {
        nextImageIndex = 0;
    }

    // get the InvisibleToVisible storyboard and start it
    Storyboard sb = FindResource("InvisibleToVisible") as Storyboard;
    if(sb != null) 
        sb.Begin(this);

}

private void InvisibleToVisible_Completed(object sender, EventArgs e)
{
    // change the source of the myImage2 to the next image to be shown
    // and increase the nextImageIndex
    this.myImage2.Source = images[nextImageIndex++];

    // if the nextImageIndex exceeds the top bound of the ocllection, 
    // get it to 0 so as to show the first image next time
    if (nextImageIndex == images.Count)
    {
        nextImageIndex = 0;
    }

    // get the VisibleToInvisible storyboard and start it
    Storyboard sb = this.FindResource("VisibleToInvisible") as Storyboard;
    if(sb != null) 
        sb.Begin(this);
}   
저작자 표시 비영리 변경 금지
신고
Posted by xyzlast Y2K


티스토리 툴바