首页 技术 正文
技术 2022年11月23日
0 收藏 902 点赞 3,760 浏览 3638 个字

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

程序运行环境如下:

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

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

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.Presentation
Imports Spire.Presentation.Collections
Imports Spire.Presentation.Drawing.Animation
Imports 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 Class
End Namespace

动画效果:

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850