我们在创建Powerpoint文档时,系统默认的幻灯片是空白背景的,很多时候我们需要自定义幻灯片背景,以达到美观的文档效果。在下面的示例中将介绍给PowerPoint幻灯片设置背景的方法,主要包含以下三个部分:
添加纯色背景添加渐变色背景添加图片作为背景所需工具
Free Spire.Presentation for .NET 版本3.3 (社区版)示例代码(供参考)
步骤 1 :添加如下using指令
using Spire.Presentation; Spire.Presentation.Drawing;using System.Drawing;
步骤 2 :创建文档
Presentation ppt = new Presentation();ppt.LoadFromfile("test.pptx");
步骤 3 :添加纯色背景
//设置文档的背景填充模式为纯色填充ppt.SlIDes[0].SlIDeBackground.Type = BackgroundType.Custom;ppt.SlIDes[0].SlIDeBackground.Fill.FillType = FillFormatType.solID;ppt.SlIDes[0].SlIDeBackground.Fill.solIDcolor.color = color.Pink;
步骤 4 :添加渐变背景色
设置文档的背景填充模式为渐变色填充ppt.SlIDes[1].SlIDeBackground.Type =1].SlIDeBackground.Fill.FillType = FillFormatType.GradIEnt;ppt.SlIDes[1].SlIDeBackground.Fill.GradIEnt.GradIEntStops.Append(0f,KNowncolors.Yellow);ppt.SlIDes[1].SlIDeBackground.Fill.GradIEnt.GradIEntStops.Append(1f,KNowncolors.Orange);
步骤 5 :添加图片作为背景
设置幻灯片背景色为图片背景ppt.SlIDes[2].SlIDeBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;ppt.SlIDes[2].SlIDeBackground.Fill.FillType = FillFormatType.Picture;ppt.SlIDes[2].SlIDeBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;加载图片作为幻灯片背景Image img = Image.Fromfile(green.png");IImageData image = ppt.Images.Append(img);ppt.SlIDes[2].SlIDeBackground.Fill.PictureFill.Picture.EmbedImage = image;
步骤6 :保存文件
ppt.Savetofile(result.pptx,fileFormat.Pptx2010);System.Diagnostics.Process.Start(");
完成代码后,调试运行程序,生成文件,如下:
全部代码:
System.Drawing;namespace AddBackground_PPT{ class Program { static voID Main(string[] args) { 实例化Presentation类,加载PowerPoint文档 Presentation ppt = Presentation(); ppt.LoadFromfile(); 设置文档的背景填充模式为纯色填充 ppt.SlIDes[ BackgroundType.Custom; ppt.SlIDes[ FillFormatType.solID; ppt.SlIDes[0].SlIDeBackground.Fill.solIDcolor.color = color.Pink; 设置文档的背景填充模式为渐变色填充 ppt.SlIDes[ FillFormatType.GradIEnt; ppt.SlIDes[].SlIDeBackground.Fill.GradIEnt.GradIEntStops.Append(1f,KNowncolors.Orange); 设置幻灯片背景色为图片背景 ppt.SlIDes[ Spire.Presentation.Drawing.BackgroundType.Custom; ppt.SlIDes[ FillFormatType.Picture; ppt.SlIDes[ PictureFillType.Stretch; 加载图片作为幻灯片背景 Image img = Image.Fromfile(); IImageData image = ppt.Images.Append(img); ppt.SlIDes[2].SlIDeBackground.Fill.PictureFill.Picture.EmbedImage = image; 保存并打开文档 ppt.Savetofile(); } }}VIEw Code
本文完。
如需转载,请注明出处!!
总结以上是内存溢出为你收集整理的C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)全部内容,希望文章能够帮你解决C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)