C#/VB.NET 自定義PPT動(dòng)畫路徑的步驟
PPT中的動(dòng)畫效果可分為已有內(nèi)置動(dòng)畫以及自定義動(dòng)畫。設(shè)置內(nèi)置動(dòng)畫,只需直接指定動(dòng)畫效果類型即可。本文主要介紹如何實(shí)現(xiàn)自定義動(dòng)畫,即自定義形狀動(dòng)作線性路徑。附C#及VB.NET代碼供參考。
程序運(yùn)行環(huán)境如下:
- .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) { //創(chuàng)建一個(gè)幻燈片文檔(新建的文檔已默認(rèn)包含一頁(yè)幻燈片) Presentation ppt = new Presentation(); ISlide slide = ppt.Slides[0];//獲取第一頁(yè)空白幻燈片 //添加形狀(指定形狀坐標(biāo)、大小及相關(guān)格式設(shè)置) 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; //給形狀設(shè)置動(dòng)畫效果 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()) '創(chuàng)建一個(gè)幻燈片文檔(新建的文檔已默認(rèn)包含一頁(yè)幻燈片) Dim ppt As New Presentation() Dim slide As ISlide = ppt.Slides(0) '獲取第一頁(yè)空白幻燈片 '添加形狀(指定形狀坐標(biāo)、大小及相關(guān)格式設(shè)置) 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 '給形狀設(shè)置動(dòng)畫效果 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
動(dòng)畫效果:
以上就是C#/VB.NET 自定義PPT動(dòng)畫路徑的步驟的詳細(xì)內(nèi)容,更多關(guān)于C#/VB.NET 自定義PPT動(dòng)畫路徑的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- C# 多進(jìn)程打開(kāi)PPT的示例教程
- C# / VB.NET 在PPT中創(chuàng)建、編輯PPT SmartArt圖形的方法詳解
- C# 實(shí)現(xiàn)PPT 每一頁(yè)轉(zhuǎn)成圖片過(guò)程解析
- C#將PPT文件轉(zhuǎn)換成PDF文件
- C#如何添加PPT背景
- C# 實(shí)現(xiàn)對(duì)PPT文檔加密、解密及重置密碼的操作方法
- C#提取PPT文本和圖片的實(shí)現(xiàn)方法
- C# 使用Free Spire.Presentation 實(shí)現(xiàn)對(duì)PPT插入、編輯、刪除表格
- 在C#里面給PPT文檔添加注釋的實(shí)現(xiàn)代碼
- C#向PPT文檔插入圖片以及導(dǎo)出圖片的實(shí)例
- C#實(shí)現(xiàn)將PPT轉(zhuǎn)換成HTML的方法
- word ppt excel文檔轉(zhuǎn)換成pdf的C#實(shí)現(xiàn)代碼
相關(guān)文章
winform 調(diào)用攝像頭掃碼識(shí)別二維碼的實(shí)現(xiàn)步驟
這篇文章主要介紹了winform 調(diào)用攝像頭掃碼識(shí)別二維碼的實(shí)現(xiàn)步驟,幫助大家更好的理解和學(xué)習(xí)使用winform,感興趣的朋友可以了解下2021-02-02C#無(wú)損高質(zhì)量壓縮圖片實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了C#無(wú)損高質(zhì)量壓縮圖片的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05C# Ado.net實(shí)現(xiàn)讀取SQLServer數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程列表及參數(shù)信息示例
這篇文章主要介紹了C# Ado.net實(shí)現(xiàn)讀取SQLServer數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程列表及參數(shù)信息,結(jié)合實(shí)例形式總結(jié)分析了C#針對(duì)SQLServer數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程及參數(shù)信息的各種常見(jiàn)操作技巧,需要的朋友可以參考下2019-02-02C#實(shí)現(xiàn)獲取Excel中圖片所在坐標(biāo)位置
本文以C#和vb.net代碼示例展示如何來(lái)獲取Excel工作表中圖片的坐標(biāo)位置,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-04-04小白2分鐘學(xué)會(huì)Visual Studio如何將引用包打包到NuGet上
這篇文章主要介紹了小白2分鐘學(xué)會(huì)Visual Studio如何將引用包打包到NuGet上,只需兩步完成打包上傳操作,需要的朋友可以參考下2021-09-09