日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用动画播放文件夹中的图片

發布時間:2024/9/20 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用动画播放文件夹中的图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
說明:(1)使用Visual Studio 2010新建一個WPF應用程序項目,
(2)然后將WPF項目名稱保存為:WpfApplication1,
(3)接著將下面的代碼復制到MainWindow.cs文件中
(4)在C:\盤根目錄下新建一個文件夾,名稱為temp
(5)將需要播放的圖片復制到該文件夾下。
(6)編譯運行程序即可。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.IO;
?
namespace WpfApplication1
{
??? /// <summary>
??? /// MainWindow.xaml 的交互邏輯
??? /// </summary>
??? public partial class MainWindow : Window
??? {
??????? Storyboard myStoryboard;
??????? Storyboard ibstoryboard;
??????? string[] files;
?
??????? Image myImage;
??????? public MainWindow()
??????? {
??????????? InitializeComponent();
??????????? GetImageFileInfo();
?
??????????? NameScope.SetNameScope(this, new NameScope());????????????
??????????? StackPanel myPanel = new StackPanel();
??????????? myPanel.Margin = new Thickness(10);
??????????? this.Title = "淡入淡出特效顯示";
??????????? this.WindowState = WindowState.Maximized;
??????????? this.WindowStyle = System.Windows.WindowStyle.None;???????????? this.Topmost = true;
??????????? myImage = new Image();
??????????? myImage.Name = "myImage";
?
??????????? this.RegisterName(myImage.Name, myImage);
??????????? myImage.Width = SystemParameters.PrimaryScreenWidth; ;
??????????? myImage.Height = SystemParameters.PrimaryScreenHeight;
?
??????????? ObjectAnimationUsingKeyFrames myObjectAnimation = new
ObjectAnimationUsingKeyFrames();
??????????? myObjectAnimation.Duration = new Duration(TimeSpan.FromSeconds(25));
??????????? for (int i = 0; i < files.Length; i++)
??????????? {
??????????????? ImageBrush ib = new ImageBrush();
??????????????? ib.ImageSource = new BitmapImage(new Uri(files[i].ToString()));
??????????????? myObjectAnimation.KeyFrames.Add(new
DiscreteObjectKeyFrame(ib.ImageSource,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(5 * i))));
??????????? }
??????????? myObjectAnimation.AutoReverse = true;
??????????? myObjectAnimation.RepeatBehavior = RepeatBehavior.Forever;
??????????? Storyboard.SetTargetName(myObjectAnimation, myImage.Name);
??????????? Storyboard.SetTargetProperty(myObjectAnimation, new
PropertyPath(Image.SourceProperty));
??????????? ibstoryboard = new Storyboard();
??????????? ibstoryboard.Children.Add(myObjectAnimation);
?
??????????? DoubleAnimation myDoubleAnimation = new DoubleAnimation();
??????????? myDoubleAnimation.From = 0.0;
??????????? myDoubleAnimation.To = 1.0;
??????????? myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
??????????? myDoubleAnimation.AutoReverse = true;
??????????? myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
?
??????????? myStoryboard = new Storyboard();
??????????? myStoryboard.Children.Add(myDoubleAnimation);
??????????? Storyboard.SetTargetName(myDoubleAnimation, myImage.Name);
??????????? Storyboard.SetTargetProperty(myDoubleAnimation, new
PropertyPath(Image.OpacityProperty));
?
??????????? // Use the Loaded event to start the Storyboard.
??????????? myImage.Loaded += new RoutedEventHandler(myImageLoaded);
?
??????????? myPanel.Children.Add(myImage);
??????????? this.Content = myPanel;???????? }
??????? private void myImageLoaded(object sender, RoutedEventArgs e)
??????? {
??????????? myStoryboard.Begin(this);
??????????? ibstoryboard.Begin(this);
??????? }
??????? private void GetImageFileInfo()
??????? {???????????????????????
??????????? string temp = @"c:\temp\";
??????????? files = Directory.GetFiles(temp, "*.jpg");
??????? }
?
??????? private void Window_KeyDown(object sender, KeyEventArgs e)
??????? {
??????????? if (e.Key == Key.Escape)
??????????? {
??????????????? MessageBoxResult yesno;
??????????????? yesno = MessageBox.Show("確定要退出程序嗎?","退出程序提示
",MessageBoxButton.YesNo);
??????????????? if(yesno == MessageBoxResult.Yes)
??????????????????? this.Close();???????????????
?
??????????? }
??????? }
?
??? }
}
?

轉載于:https://www.cnblogs.com/dodui/archive/2012/03/29/2423223.html

總結

以上是生活随笔為你收集整理的使用动画播放文件夹中的图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。