我们在创建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. ubuntu18.04新体验

    虽然ubuntu18.04LST版本早出来了,但自己原来的ubuntu16.04还可以用,就懒得折腾了. 但最近ubuntu崩了,就想尝尝鲜...结果发现还挺好用的,准确地说,ubuntu是越来越好用 ...

  2. mybatis的基本语句的应用

    大家好今晚整理有关mybatis的添加删除修改更新的操作 一.select <!-- 查询学生,根据id --> <select id="getStudent" ...

  3. cadence焊盘及元件封装制作

    前面学习了元件封装的制作,由于琐碎事情的耽误,加上学习python,没有及时的总结这部分内容,现在做一个补充!

  4. Document APIs

    本节首先简要介绍Elasticsearch的数据复制模型,然后详细描述以下CRUD API: Single document APIs Index API Get API Delete API Upd ...

  5. changXY

    changXY <!DOCTYPE html> <html> <head> <link rel="shortcut icon" href= ...

  6. H5混合开发问题总结

    1.This application is modifying the autolayout engine from a background thread, which can lead to en ...

  7. FTP出现PORT模式成功, 请更新你的站点配置文件

    最近用FTP连接站点,经常出现连接不上或者连接失败,提示以PASV模式连接失败,正在使用PORT模式连接,最后才能连接成功,连接时间也是相当长,又慢又不稳定.   工具/原料   FlashFXP等F ...

  8. Centos7 Nginx开机启动

    1.简易安装nginx: ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf ...

  9. ansible基础-roles

    一 简介 注:本文demo使用ansible2.7稳定版 在我看来,role是task文件.变量文件.handlers文件的集合体,这个集合体的显著特点是:可移植性和可重复执行性. 实践中,通常我们以 ...

  10. [Swift]LeetCode187. 重复的DNA序列 | Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...