C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)
我们在创建Powerpoint文档时,系统默认的幻灯片是空白背景的,很多时候我们需要自定义幻灯片背景,以达到美观的文档效果。在下面的示例中将介绍给PowerPoint幻灯片设置背景的方法,主要包含以下三个部分:
- 添加纯色背景
- 添加渐变色背景
- 添加图片作为背景
所需工具
示例代码(供参考)
步骤 1 :添加如下using指令
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
步骤 2 :创建文档
Presentation ppt = new Presentation();
ppt.LoadFromFile("test.pptx");
步骤 3 :添加纯色背景
//设置文档的背景填充模式为纯色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Solid;
ppt.Slides[].SlideBackground.Fill.SolidColor.Color = Color.Pink;
步骤 4 :添加渐变背景色
//设置文档的背景填充模式为渐变色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Gradient;
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow);
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange);
步骤 5 :添加图片作为背景
//设置幻灯片背景色为图片背景
ppt.Slides[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
//加载图片作为幻灯片背景
Image img = Image.FromFile("green.png");
IImageData image = ppt.Images.Append(img);
ppt.Slides[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
步骤6 :保存文件
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
完成代码后,调试运行程序,生成文件,如下:

全部代码:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing; namespace AddBackground_PPT
{
class Program
{
static void Main(string[] args)
{
//实例化Presentation类,加载PowerPoint文档
Presentation ppt = new Presentation();
ppt.LoadFromFile("test.pptx"); //设置文档的背景填充模式为纯色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Solid;
ppt.Slides[].SlideBackground.Fill.SolidColor.Color = Color.Pink; //设置文档的背景填充模式为渐变色填充
ppt.Slides[].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Gradient;
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow);
ppt.Slides[].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange); //设置幻灯片背景色为图片背景
ppt.Slides[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
//加载图片作为幻灯片背景
Image img = Image.FromFile("green.png");
IImageData image = ppt.Images.Append(img);
ppt.Slides[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; //保存并打开文档
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
}
}
}
本文完。
如需转载,请注明出处!!
C# 如何添加PPT背景(纯色背景、渐变色背景、图片背景)的更多相关文章
- Java设置PPT幻灯片背景——纯色、渐变、图片背景
PPT幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充.本文将对此介绍具体实现方法. 使用工具:Free Spire.Presentation fo ...
- Android 设置按钮背景透明与半透明_图片背景透明
Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... /> 透明 ...
- C# 设置Word文档背景(纯色/渐变/图片背景)
Word是我们日常生活.学习和工作中必不可少的文档处理工具.精致美观的文档能给人带来阅读时视觉上的美感.在本篇文章中,将介绍如何使用组件Free Spire.Doc for .NET(社区版)给Wor ...
- C# 给PDF添加图片背景
C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...
- iOS 图片背景模糊效果
iOS 图片背景模糊效果 1.使用CoreImage中的模糊滤镜 原始效果图如下: CoreImage的实现: - (void)viewDidLoad { [super viewDidLoad]; / ...
- Atitit 动态按钮图片背景颜色与文字组合解决方案
Atitit 动态按钮图片背景颜色与文字组合解决方案 转换背景颜色,setFont("cywe_img", fontScale, 50, 5) 设置文字大小与坐标 文字分拆,使用字 ...
- CSS背景100%平铺 浏览器缩小背景显示不全解决办法
本文我们分享前端CSS背景100%平铺,浏览器缩小背景显示不全bug解决的两个方法,如果你也遇到了,那么就可以参考下面文章. 把浏览器的窗口缩小时,拖动滚动条时你会发现原本设定的CSS背景100%平铺 ...
- IOS中设置cell的背景view和选中时的背景view 、设置cell最右边的指示器(比如箭头\文本标签)
一.Cell的设置 1.设置cell的背景view和选中时的背景view UIImageView *bg = [[UIImageView alloc] init]; bg.image = [UIIma ...
- jquery 图片背景透明度(支持IE5/IE6/IE7)
设置背景图片,以突出透明度的效果及jquery png背景透明插件实例教程 <head> <title>toggle()</title> <style typ ...
随机推荐
- Cordova/Ionic Android 开发环境搭建 - Windows系统
电脑操作系统 - windows 10 IDE - WebStorm 2019 Node v10.15.3 npm v6.4.1 Ionic v3 Angula v5 Cordova 移动设备 ...
- git命令别名(Alias)
每次切换分支: git ckeckout branch_name 等命令费时又费力,git 别名配置起来: 别名配置: git config --global alias.ck ckeckout 其他 ...
- Java实现递增数组的二分查找
package com.algorithm; import java.util.ArrayList;import java.util.List; /** * 类功能描述: * * @author Ba ...
- JDK设计模式之—动态代理
代理模式的特点 代理模式是常用的java设计模式,它的特征是代理类与委托类有同样的接口.代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类. 代理类的对象并不是真正实现服务,而是通过调用委 ...
- [Swift]LeetCode227. 基本计算器 II | Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- [Swift]LeetCode250.计数相同值子树的个数 $ Count Univalue Subtrees
Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...
- 编译安装mysql5.7.24踩的坑
1.报错如下:CMake Error at cmake/boost.cmake:76 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 - ...
- 开始使用Filebeat
认识Beats Beats是用于单用途数据托运人的平台.它们以轻量级代理的形式安装,并将来自成百上千台机器的数据发送到Logstash或Elasticsearch. (画外音:通俗地理解,就是采集数据 ...
- Solr 12 - 部署SolrCloud中遇到的问题 + 解决方法
目录 1 ZooKeeper管理配置文件的另一种方法 2 Solr服务不能访问 3 部分节点处于"Recovering"或"Gone"状态 4 Solr集群不稳 ...
- Android Native App自动化测试实战讲解(下)(基于python)
6.Appuim自动化测试框架API讲解与案例实践(三) 如图1,可以在主函数里通过TestSuite来指定执行某一个测试用例: 6.1,scroll():如图2 从图3中可以看到当前页面的所有元素r ...