博客
关于我
C#/VB.NET 自定义动画路径
阅读量:421 次
发布时间:2019-03-06

本文共 4512 字,大约阅读时间需要 15 分钟。

PPT中的动画效果可分为已有内置动画以及自定义动画。设置内置动画,只需直接指定动画效果类型即可。本文主要介绍如何实现自定义动画,即自定义形状动作线性路径。附C#及VB.NET代码供参考。

程序运行环境如下:

  • .Net Framework 4.8
  • Visual Studio
  • Spire.Presentation.dll

所需引用的必要程序集文件如下图:

C#

using Spire.Presentation;using Spire.Presentation.Collections;using Spire.Presentation.Drawing.Animation;using System.Drawing;namespace CustomAnimation{    class Program    {        static void Main(string[] args)        {            //创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)            Presentation ppt = new Presentation();            ISlide slide = ppt.Slides[0];//获取第一页空白幻灯片            //添加形状(指定形状坐标、大小及相关格式设置)            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 50, 180, 180));            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient;            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue);            shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink);            shape.ShapeStyle.LineColor.Color = Color.White;            //给形状设置动画效果            AnimationEffect effect = ppt.Slides[0].Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser);            CommonBehaviorCollection common = effect.CommonBehaviorCollection;            AnimationMotion motion = (AnimationMotion)common[0];            motion.Origin = AnimationMotionOrigin.Layout;            motion.PathEditMode = AnimationMotionPathEditMode.Relative;            MotionPath moinPath = new MotionPath();            moinPath.Add(MotionCommandPathType.MoveTo, new PointF[] { new PointF(0, 0) }, MotionPathPointsType.CurveAuto, true);            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.18f, 0.18f) }, MotionPathPointsType.CurveAuto, true);            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(-0.1f, 0.2f) }, MotionPathPointsType.CurveAuto, true);            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.25f, 0.2f) }, MotionPathPointsType.CurveAuto, true);            moinPath.Add(MotionCommandPathType.End, new PointF[] { }, MotionPathPointsType.CurveStraight, true);            motion.Path = moinPath;            //保存文档            ppt.SaveToFile("CustomAnimation.pptx", FileFormat.Pptx2013);            System.Diagnostics.Process.Start("CustomAnimation.pptx");        }    }}

 

VB.NET

Imports Spire.PresentationImports Spire.Presentation.CollectionsImports Spire.Presentation.Drawing.AnimationImports System.DrawingNamespace CustomAnimation    Class Program        Private Shared Sub Main(args As String())            '创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)            Dim ppt As New Presentation()            Dim slide As ISlide = ppt.Slides(0)            '获取第一页空白幻灯片            '添加形状(指定形状坐标、大小及相关格式设置)            Dim shape As IAutoShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, New RectangleF(100, 50, 180, 180))            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue)            shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink)            shape.ShapeStyle.LineColor.Color = Color.White            '给形状设置动画效果            Dim effect As AnimationEffect = ppt.Slides(0).Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser)            Dim common As CommonBehaviorCollection = effect.CommonBehaviorCollection            Dim motion As AnimationMotion = DirectCast(common(0), AnimationMotion)            motion.Origin = AnimationMotionOrigin.Layout            motion.PathEditMode = AnimationMotionPathEditMode.Relative            Dim moinPath As New MotionPath()            moinPath.Add(MotionCommandPathType.MoveTo, New PointF() {New PointF(0, 0)}, MotionPathPointsType.CurveAuto, True)            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.18F, 0.18F)}, MotionPathPointsType.CurveAuto, True)            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(-0.1F, 0.2F)}, MotionPathPointsType.CurveAuto, True)            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.25F, 0.2F)}, MotionPathPointsType.CurveAuto, True)            moinPath.Add(MotionCommandPathType.[End], New PointF() {}, MotionPathPointsType.CurveStraight, True)            motion.Path = moinPath            '保存文档            ppt.SaveToFile("CustomAnimation.pptx", FileFormat.Pptx2013)            System.Diagnostics.Process.Start("CustomAnimation.pptx")        End Sub    End ClassEnd Namespace

动画效果:

 

原创内容,转载务必注明出处!

 

你可能感兴趣的文章
Mysql中常用函数的使用示例
查看>>
MySql中怎样使用case-when实现判断查询结果返回
查看>>
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>
mysql中的collate关键字是什么意思?
查看>>
MySql中的concat()相关函数
查看>>
mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
查看>>
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>