说明:(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. pytorch笔记:Dataloader
  2. 【django】创建django项目工程
  3. springboot1——第一个springboot程序
  4. java in thread main_JAVA报错:Exception in thread main……求帮助?
  5. 小敏同学利用计算机设计,福建省晋江一中、华侨中学2015-2016学年七年级数学上学期期中质量检测试题(无答案) 华东师大版...
  6. Rust: trait 孤儿规则
  7. Win7 + VirtualBox安装Mac OS X雪豹操作系统图文详解[转]
  8. 算术平均数及几何平均数
  9. Mockjs-官网学习总结
  10. TypeError: catching classes that do not inherit from BaseException is not allowed
  11. 算法第一章作业(c++代码规范+数学之美读后感+规划)
  12. 【免费使用】【redis】【数据库】快速使用redislabs免费套餐 注册和配置redis 缓存 数据库 nosql
  13. java中方法的使用
  14. vue项目读取显示pdf文件
  15. linux uniq去重不生效
  16. php代码着色器,使用Shader Graph实现《塞尔达传说:旷野之息》风格的着色器(转)...
  17. 「中国加班第一楼」深圳科兴万人大撤离!拖主机带屏幕,程序员公交上写代码!...
  18. 正则表达式案例练习-封装工具函数歌词解析和时间格式化
  19. C# 服务端监听客户端连接
  20. 阿里云查看mysql数据库密码是多少_阿里云服务器查看数据库密码是多少

热门文章

  1. C++在数字N中找到精确除以N的数字的算法(附完整源码)
  2. OpenGL Texture Coordinate Wrapping纹理坐标包装的实例
  3. OpenGL地形渲染
  4. C++重载运算符最好声明为友元
  5. QT的QWGLNativeContext类的使用
  6. 经典C语言程序100例之二八
  7. 46栈内存溢出、内存区域(程序计数器、Java 虚拟机栈、本地方法栈、Java 堆、方法区、直接内存、内存溢出)与内存溢出(对象实例化分析)
  8. 44_pytorch数据增强,Resize,Flip,Rotate,Random Move Crop,Scale,Crop Part,Noise
  9. 02_Flink vs storm vs SparkStreaming、Flink vs storm对比图、实时框架如何选择
  10. 02_pandas获取数据(指定列获取、[]方式获取、loc函数,at函数, iloc函数 iat函数)