说明:(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

使用动画播放文件夹中的图片相关推荐

  1. Excel插件,按条件从文件夹中筛选图片文件

    按条件从文件夹中筛选图片文件 E灵,动画教材: 按条件从文件夹中筛选图片文件

  2. matlab读取一个文件的图片大小,Matlab读取文件夹中子文件夹中的图片并修改尺寸...

    今天被师兄问到如何利用matlab批处理图片,觉得很简单嘛 就让他去百度 结果只百度到处理文件夹中图片的程序 好吧 这里放上如何处理文件夹中子文件夹的图片 现状:在一个名为casia的文件夹中,里面有 ...

  3. python opencv 实现从一个文件夹中读取图片做切割处理后放入另一个文件夹

    python opencv 实现从一个文件夹中读取图片切割处理后放入另一个文件夹. 实现的功能是把一个文件夹里的图片作处理,即把原图片中心为起点切割成1536*1536的图片,原图片必须大于这个的大小 ...

  4. 如何批量导入不同文件夹中的图片

    在标签设计印刷工作中,批量导入图片已经是非常普遍的功能了.不论图片名称是否有规律或者是否有在数据库中保存,经过一些专业的设置都可以实现批量导入.那么如果是不同文件夹中的图片该如何导入呢? 文件夹中图片 ...

  5. 使用Python读取文件夹中的图片

    文章目录 Python创建新的文件夹 Python读取文件夹中的图片内容以及存取   一个文件夹中含有大量的图片文件,jpg格式和png格式的.需要从中选出一些比较适合电脑分辨率的,也就是宽度大于高度 ...

  6. java判断文件夹中的图片是否重复

    java判断文件夹中的图片是否重复 直接上代码 package com.example.common; import java.io.File; import java.io.FileInputStr ...

  7. win7文件夹中的图片使用“XX图标”查看模式显示时,无法正常显示图片缩略图

    win7文件夹中的图片使用"XX图标"查看模式显示时,无法正常显示图片缩略图 系统: win7 详细症状描述: 进入含有图片的文件夹,选择"查看"菜单栏中的&q ...

  8. python 按照顺序读取文件夹中的图片名称

    前言: 在ubuntu16.04系统中,读取图像名称的时候,往往会出现乱序的现象,比如: 1,2,3,4,5,6,7,8,9,10 可能会被提取到的顺序为: 1,10,2,3,4,5,6,7,8,9 ...

  9. 【批量改文件夹中的图片名称-python】

    批量改文件夹中的图片名称-python(记录) 目的 最近在制作零件数据集标注时,发现在摄像机中拍摄的图片名称是乱码的,不便于进行数据标注,所以写下这段代码,以便日后再次使用. 转换之前图片文件夹中的 ...

最新文章

  1. 允许使用抽象类类型 isearchboxinfo 的对象_Java新手必学:面向对象的特性都有哪些?...
  2. 物体的三维识别与6D位姿估计:PPF系列论文介绍(五)
  3. pytorch实现手写数字识别_Paddle和Pytorch实现MNIST手写数字集识别对比
  4. exportfs命令、NFS客户端问题、FTP介绍、使用vsftpd搭建ftp
  5. 【Linux】tcp缓冲区大小的默认值、最大值
  6. 多学科可行法matlab,微小卫星多学科建模与仿真方法研究
  7. 计算机科学入门指南游戏攻略,【基础攻略】从零开始新手入门指南
  8. 洛谷 P1352 没有上司的舞会(树形 DP)
  9. 面试时如何优雅地自我介绍?
  10. 如何持之以恒做好一件事?
  11. 用html还是xml做网页好,XML与HTML的比较
  12. snipaste如何滚动截图_每天都在用的QQ截图,居然升级了这么多实用功能!
  13. 云原生火爆技术人朋友圈,你可别云里雾里了!
  14. vector内存分配和回收机制
  15. Raki的网络流24题题解总结
  16. matlab与测绘数据处理,MATLAB与测绘数据处理
  17. 阿里云 Aliplayer高级功能介绍(三):多字幕 1
  18. 纹理基础知识和过滤模式详解
  19. AMBA总线协议之AHB学习记录(1)—ahb_bus(附verilog代码)
  20. 大数据Spark超经典视频链接全集

热门文章

  1. VTK:PolyData之GeometryFilter
  2. Qt Creator造型Modeling
  3. C语言实现AVL树(附完整源码)
  4. 03_ClickHouse数据格式,TabSeparated、TSKV、CSV格式、JSON格式、Parquet、ORC、其它数据格式(Native,Pretty,Values,Vertical等)
  5. MySQL MMM多主多从搭建
  6. CentOS7 64位下MySQL5.7安装与配置(YUM)
  7. HDFS的工作机制,HDFS写数据流程,HDFS读数据流程(来自学习资料)
  8. 1.httpClient和ScrollView
  9. 线性渐变(linear-gradient)
  10. 关于WebService中用到的QName详解