我们在创建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背景(纯色背景、渐变色背景、图片背景)的更多相关文章

  1. Java设置PPT幻灯片背景——纯色、渐变、图片背景

    PPT幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充.本文将对此介绍具体实现方法. 使用工具:Free Spire.Presentation fo ...

  2. Android 设置按钮背景透明与半透明_图片背景透明

    Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... />  透明 ...

  3. C# 设置Word文档背景(纯色/渐变/图片背景)

    Word是我们日常生活.学习和工作中必不可少的文档处理工具.精致美观的文档能给人带来阅读时视觉上的美感.在本篇文章中,将介绍如何使用组件Free Spire.Doc for .NET(社区版)给Wor ...

  4. C# 给PDF添加图片背景

    C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...

  5. iOS 图片背景模糊效果

    iOS 图片背景模糊效果 1.使用CoreImage中的模糊滤镜 原始效果图如下: CoreImage的实现: - (void)viewDidLoad { [super viewDidLoad]; / ...

  6. Atitit 动态按钮图片背景颜色与文字组合解决方案

    Atitit 动态按钮图片背景颜色与文字组合解决方案 转换背景颜色,setFont("cywe_img", fontScale, 50, 5) 设置文字大小与坐标 文字分拆,使用字 ...

  7. CSS背景100%平铺 浏览器缩小背景显示不全解决办法

    本文我们分享前端CSS背景100%平铺,浏览器缩小背景显示不全bug解决的两个方法,如果你也遇到了,那么就可以参考下面文章. 把浏览器的窗口缩小时,拖动滚动条时你会发现原本设定的CSS背景100%平铺 ...

  8. IOS中设置cell的背景view和选中时的背景view 、设置cell最右边的指示器(比如箭头\文本标签)

    一.Cell的设置 1.设置cell的背景view和选中时的背景view UIImageView *bg = [[UIImageView alloc] init]; bg.image = [UIIma ...

  9. jquery 图片背景透明度(支持IE5/IE6/IE7)

    设置背景图片,以突出透明度的效果及jquery png背景透明插件实例教程 <head> <title>toggle()</title> <style typ ...

随机推荐

  1. python elasticsearch 批量写入数据

    from elasticsearch import Elasticsearch from elasticsearch import helpers import pymysql import time ...

  2. ES6新增对象方法的访问描述符:get(只读)、set(只写)

    Es6新增对象方法的访问描述符:get(只读).set(只写),可以直接使用,一般用于数据监听,用途类似于vue.$watch. var obj = { a:1, get bar() { return ...

  3. hibernate框架搭建

    hibernate框架的搭建步骤: 1.导包 2.创建数据库准备表 3.书写orm元数据(对象与表的映射配置文件) 4.书写配置文件 5.书写代码测试 一.导包: 创建web-maven工程添加hib ...

  4. RHEL7 配置网络yum源

    redhat系统安装好尽管默认带有yum,但是redhat的更新包只对注册用户有效(收费).所以需要更换yum源. 基本的流程就是: 1.删除redhat7.0系统自带的yum软件包: 2.自行下载所 ...

  5. js操作DOM对象

    js操作DOM对象  (Document Object Model)文档对象模型 nodeType返回值 1:元素节点 2:属性节点 3:文本节点 8:注释节点 9: 文档节点 nodeName 节点 ...

  6. 琐事集 vol 2

    vol 2-0 宝宝,你是不是该看书咯? 她正瘫在沙发上看剧 我刚提起看书,她惊恐地看了看我 然后眼白一翻,彻底地瘫平了 宝宝? “宝宝睡着了.” 你下周就要考护师了!很难得,她认真地睁开眼,信誓旦旦 ...

  7. Javascript高级编程学习笔记(89)—— Canvas(6) 变换

    变换 通过上下文的变化,可以对图像进行处理后再将其绘制到画布上 当我们创建上下文时,会以默认值初始化变化矩阵,在默认的变换矩阵下所有处理都按描述直接绘制. 而当我们为上下文应用变换时,会导致使用不同的 ...

  8. [Swift]LeetCode70. 爬楼梯 | Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  9. [Swift]LeetCode877. 石子游戏 | Stone Game

    Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, ...

  10. Android开发:修改eclipse里的Android虚拟机路径

    一.发现问题: 今天打开电脑发现C盘缩了不少,这才意识到:eclipse里配置的安卓虚拟机默认放在了C盘里. 当然,在不同的电脑上可能路径有所不同,我的默认路径是:C:\Users\lenovo\.a ...