ms powerpoint可以对填充在图形中的图片进行透明设置,使图形中的文字能显示于图片上方而不受图片内容的干扰。本文将展示如何使用spire.presetation,在powerpoint中添加图片并设置透明度。
c#
//创建powerpoint文档
presentation presentation = new presentation();
//加载图片到image对象
string imagepath = "background.png";
image image = image.fromfile(imagepath);
//获取图片长宽
float width = image.width;
float height = image.height;
//添加图形到幻灯片
rectanglef rect = new rectanglef(50, 50, width, height);
iautoshape shape = presentation.slides[0].shapes.appendshape(shapetype.rectangle, rect);
shape.line.filltype = fillformattype.none;
//用图片填充图形
shape.fill.filltype = fillformattype.picture;
shape.fill.picturefill.picture.url = imagepath;
shape.fill.picturefill.filltype = picturefilltype.stretch;
//设置图片透明度(0-100)
shape.fill.picturefill.picture.transparency = 70;
//在图形上添加文字
shape.textframe.text = "知识就是力量";
shape.textframe.textrange.isbold = tristate.true;
shape.textframe.textrange.fill.filltype = fillformattype.solid;
shape.textframe.textrange.fill.solidcolor.color = color.black;
shape.textframe.textrange.fontheight = 30f;
//保存文档
presentation.savetofile("output.pptx", fileformat.pptx2013);
vb.net
'创建powerpoint文档
dim presentation as new presentation()
'加载图片到image对象
dim imagepath as string = "background.png"
dim image__1 as image = image.fromfile(imagepath)
'获取图片长宽
dim width as single = image__1.width
dim height as single = image__1.height
'添加图形到幻灯片
dim rect as new rectanglef(50, 50, width, height)
dim shape as iautoshape = presentation.slides(0).shapes.appendshape(shapetype.rectangle, rect)
shape.line.filltype = fillformattype.none
'用图片填充图形
shape.fill.filltype = fillformattype.picture
shape.fill.picturefill.picture.url = imagepath
shape.fill.picturefill.filltype = picturefilltype.stretch
'设置图片透明度(0-100)
shape.fill.picturefill.picture.transparency = 70
'在图形上添加文字
shape.textframe.text = "知识就是力量"
shape.textframe.textrange.isbold = tristate.[true]
shape.textframe.textrange.fill.filltype = fillformattype.solid
shape.textframe.textrange.fill.solidcolor.color = color.black
shape.textframe.textrange.fontheight = 30f
'保存文档
presentation.savetofile("output.pptx", fileformat.pptx2013)