C#/VB.NET自定义动画路径

C#/VB.NET自定义动画路径-时光屋

程序运行环境如下:

  1. .Net Framework 4.8
  2. Visual Studio
  3. 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”);
}
}
}

C#/VB.NET自定义动画路径-时光屋

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

————下载必看————

1、资源通过互联网渠道公开获取,仅供阅读测试,请在下载后24小时内删除,谢谢合作!
2、本站解压密码统一为:yudouyudou
3、本站微信客服/失效补发:rsst58
4、若版权方认为本站侵权,请联系发邮件至(rsstime@qq.com)处理。
5、关于下载,播放声音字幕,解压等问题,请点击查看>>常见问题
时光屋 » C#/VB.NET自定义动画路径

发表评论

至臻视听_发烧收藏

会员介绍 常见问题