WPF를 이용한 Image animation
System.Windows.Media.Animation.StoryBoard controller를 이용해서 Image Animation을 할 수 있다.
Image Animation 형태는 StoryBoard Controller의 Property들을 변경시키면 가능하다.
System.Windows.Media.Animation.StoryBoard controller를 이용해서 Image Animation을 할 수 있다.
Image Animation 형태는 StoryBoard Controller의 Property들을 변경시키면 가능하다.
01.
int
nextImageIndex;
02.
List<bitmapimage> images =
new
List<bitmapimage>();
03.
04.
private
void
Window_Loaded(
object
sender, RoutedEventArgs e)
05.
{
06.
// initialize the images collection
07.
images.Add(
new
BitmapImage(
new
Uri(
"Images/image1.jpg"
, UriKind.Relative)));
08.
images.Add(
new
BitmapImage(
new
Uri(
"Images/image2.jpg"
, UriKind.Relative)));
09.
images.Add(
new
BitmapImage(
new
Uri(
"Images/image3.jpg"
, UriKind.Relative)));
10.
images.Add(
new
BitmapImage(
new
Uri(
"Images/image4.jpg"
, UriKind.Relative)));
11.
12.
nextImageIndex = 2;
13.
}
14.
15.
private
void
VisbleToInvisible_Completed(
object
sender, EventArgs e)
16.
{
17.
// change the source of the myImage1 to the next image to be shown
18.
// and increase the nextImageIndex
19.
this
.myImage1.Source = images[nextImageIndex++];
20.
21.
// if the nextImageIndex exceeds the top bound of the ocllection,
22.
// get it to 0 so as to show the first image next time
23.
if
(nextImageIndex == images.Count)
24.
{
25.
nextImageIndex = 0;
26.
}
27.
28.
// get the InvisibleToVisible storyboard and start it
29.
Storyboard sb = FindResource(
"InvisibleToVisible"
)
as
Storyboard;
30.
if
(sb !=
null
)
31.
sb.Begin(
this
);
32.
33.
}
34.
35.
private
void
InvisibleToVisible_Completed(
object
sender, EventArgs e)
36.
{
37.
// change the source of the myImage2 to the next image to be shown
38.
// and increase the nextImageIndex
39.
this
.myImage2.Source = images[nextImageIndex++];
40.
41.
// if the nextImageIndex exceeds the top bound of the ocllection,
42.
// get it to 0 so as to show the first image next time
43.
if
(nextImageIndex == images.Count)
44.
{
45.
nextImageIndex = 0;
46.
}
47.
48.
// get the VisibleToInvisible storyboard and start it
49.
Storyboard sb =
this
.FindResource(
"VisibleToInvisible"
)
as
Storyboard;
50.
if
(sb !=
null
)
51.
sb.Begin(
this
);
52.
}
53.
</bitmapimage></bitmapimage>