使用spire.presentation,开发人员可以给powerpoint文档设置背景颜色和添加背景图片。该示例将详细讲述如何使用spire.presentation给一个现有幻灯片文档设置纯色背景颜色,渐变背景颜色以及添加背景图片。
设置纯色背景颜色
c#
//加载powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//设置文档的背景填充模式为纯色填充,设置颜色
ppt.slides[0].slidebackground.type = backgroundtype.custom;
ppt.slides[0].slidebackground.fill.filltype = fillformattype.solid;
ppt.slides[0].slidebackground.fill.solidcolor.color = color.darkseagreen;
//保存文档
ppt.savetofile("solidbackground.pptx", fileformat.pptx2013);
vb.net
'加载powerpoint文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'设置文档的背景填充模式为纯色填充,设置颜色
ppt.slides(0).slidebackground.type = backgroundtype.[custom]
ppt.slides(0).slidebackground.fill.filltype = fillformattype.solid
ppt.slides(0).slidebackground.fill.solidcolor.color = color.darkseagreen
'保存文档
ppt.savetofile("solidbackground.pptx", fileformat.pptx2013)
设置渐变色背景颜色
c#
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//设置文档的背景填充模式为渐变色填充,设置颜色
ppt.slides[0].slidebackground.type = backgroundtype.custom;
ppt.slides[0].slidebackground.fill.filltype = fillformattype.gradient;
ppt.slides[0].slidebackground.fill.gradient.gradientstops.append(0f, knowncolors.white);
ppt.slides[0].slidebackground.fill.gradient.gradientstops.append(1f, knowncolors.mediumseagreen);
ppt.savetofile("gradientbackground.pptx", fileformat.pptx2013);
vb.net
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'设置文档的背景填充模式为渐变色填充,设置颜色
ppt.slides(0).slidebackground.type = backgroundtype.[custom]
ppt.slides(0).slidebackground.fill.filltype = fillformattype.gradient
ppt.slides(0).slidebackground.fill.gradient.gradientstops.append(0f, knowncolors.white)
ppt.slides(0).slidebackground.fill.gradient.gradientstops.append(1f, knowncolors.mediumseagreen)
ppt.savetofile("gradientbackground.pptx", fileformat.pptx2013)
设置背景图片
c#
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//设置文档的背景填充模式为图片填充
ppt.slides[0].slidebackground.type = spire.presentation.drawing.backgroundtype.custom;
ppt.slides[0].slidebackground.fill.filltype = fillformattype.picture;
ppt.slides[0].slidebackground.fill.picturefill.filltype = picturefilltype.stretch;
//设置背景图片
image img = image.fromfile("bgimage.jpg");
iimagedata image = ppt.images.append(img);
ppt.slides[0].slidebackground.fill.picturefill.picture.embedimage = image;
ppt.savetofile("imagebackground.pptx", fileformat.pptx2013);
vb.net
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'设置文档的背景填充模式为图片填充
ppt.slides(0).slidebackground.type = spire.presentation.drawing.backgroundtype.[custom]
ppt.slides(0).slidebackground.fill.filltype = fillformattype.picture
ppt.slides(0).slidebackground.fill.picturefill.filltype = picturefilltype.stretch
'设置背景图片
dim img as image = image.fromfile("bgimage.jpg")
dim image__1 as iimagedata = ppt.images.append(img)
ppt.slides(0).slidebackground.fill.picturefill.picture.embedimage = image__1
ppt.savetofile("imagebackground.pptx", fileformat.pptx2013)