C#/VB.NET 自定义PPT动画路径的步骤
作者:E-iceblue 时间:2022-11-25 10:07:49
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.Drawing
Namespace 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
动画效果:
来源:https://www.cnblogs.com/Yesi/archive/2021/05/08/14743875.html
标签:C#,VB.NET,PPT,动画路径
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Jackson反序列化遇到的问题及解决
2023-11-13 21:12:14
Java中的Object类用法总结
2023-06-06 11:48:36
![](https://img.aspxhome.com/file/2023/0/101910_0s.png)
Android自定义钟表特效
2022-09-11 00:29:14
![](https://img.aspxhome.com/file/2023/9/110699_0s.jpg)
关于C#10 新特性 Lambda 优化
2022-05-31 08:21:16
Java中简单实用Quartz概述
2021-09-09 14:16:30
实例代码讲解JAVA 观察者模式
2023-09-11 19:22:18
![](https://img.aspxhome.com/file/2023/9/83139_0s.jpg)
java实现斗地主发牌功能
2022-01-14 14:27:32
datatable生成excel和excel插入图片示例详解
2022-06-18 21:48:38
![](https://img.aspxhome.com/file/2023/2/116592_0s.jpg)
三十分钟快速掌握C# 6.0知识点
2022-10-15 04:26:00
Android开发中使用sqlite实现新闻收藏和取消收藏的功能
2023-01-27 18:15:13
![](https://img.aspxhome.com/file/2023/1/129011_0s.jpg)
java IO流读取图片供前台显示代码分享
2023-10-01 20:55:26
![](https://img.aspxhome.com/file/2023/2/124712_0s.png)
C#使用符号表实现查找算法
2022-08-07 01:16:45
![](https://img.aspxhome.com/file/2023/8/122678_0s.jpg)
ADO.NET实体数据模型详细介绍
2023-10-16 12:15:41
![](https://img.aspxhome.com/file/2023/1/91321_0s.jpg)
Spring中@Validated和@Valid区别浅析
2021-10-04 23:27:22
Java NIO实战之多人聊天室
2022-02-28 15:05:00
Android 自定义组件成JAR包的实现方法
2023-04-08 17:56:39
![](https://img.aspxhome.com/file/2023/0/102610_0s.png)
JavaCV实现照片马赛克效果
2023-04-27 15:55:14
![](https://img.aspxhome.com/file/2023/4/66624_0s.jpg)
c# BackgroundWorker组件的作用
2022-12-23 20:56:12
![](https://img.aspxhome.com/file/2023/5/111105_0s.jpg)
关于@Autowired注入依赖失败的问题及解决
2023-11-29 00:50:42
![](https://img.aspxhome.com/file/2023/4/60474_0s.png)
Java中的main函数的详细介绍
2021-10-03 16:09:16