在powerpoint中,可以将图形上的文字设置为半透明,使文字不至于完全遮挡其背景。文字透明程度也可以根据不同场景做相应调整。本文将展示如何使用spire.presentation为幻灯片中的文字设置不同的透明效果。
c#
//创建presentation对象
presentation ppt = new presentation();
//设置ppt页面大小(16x9模式)
ppt.slidesize.type = slidesizetype.screen16x9;
//添加图形
iautoshape textboxshape = ppt.slides[0].shapes.appendshape(shapetype.rectangle, new rectanglef(50, 70,160, 200));
//设置图形边框为透明
textboxshape.shapestyle.linecolor.color = color.transparent;
//设置图形边填充色
textboxshape.fill.filltype = fillformattype.solid;
textboxshape.fill.solidcolor.color = color.brown;
//删除默认段落
textboxshape.textframe.paragraphs.clear();
//设置透明度初始值
int alpha = 15;
//添加四个段落,并应用不同透明度的颜色
for (int i = 0; i < 4; i )
{
//添加段落
textboxshape.textframe.paragraphs.append(new textparagraph());
//添加文字
textboxshape.textframe.paragraphs[i].textranges.append(new textrange("设置文字透明度"));
//设置字体大小及名称
textboxshape.textframe.paragraphs[i].textranges[0].fontheight = 20f;
textboxshape.textframe.paragraphs[i].textranges[0].latinfont = new textfont("黑体");
//设置文字填充方式
textboxshape.textframe.paragraphs[i].textranges[0].fill.filltype = fillformattype.solid;
//通过alpha参数设定不同的颜色透明度(该值的范围为0-255),并应用到文字
textboxshape.textframe.paragraphs[i].textranges[0].fill.solidcolor.color = color.fromargb(alpha, color.white);
alpha = 80;
}
//保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013);
vb.net
'创建presentation对象
dim ppt as new presentation()
'设置ppt页面大小(16x9模式)
ppt.slidesize.type = slidesizetype.screen16x9
'添加图形
dim textboxshape as iautoshape = ppt.slides(0).shapes.appendshape(shapetype.rectangle, new rectanglef(50, 70, 160, 200))
'设置图形边框为透明
textboxshape.shapestyle.linecolor.color = color.transparent
'设置图形边填充色
textboxshape.fill.filltype = fillformattype.solid
textboxshape.fill.solidcolor.color = color.brown
'删除默认段落
textboxshape.textframe.paragraphs.clear()
'设置透明度初始值
dim alpha as integer = 15
'添加四个段落,并应用不同透明度的颜色
for i as integer = 0 to 3
'添加段落
textboxshape.textframe.paragraphs.append(new textparagraph())
'添加文字
textboxshape.textframe.paragraphs(i).textranges.append(new textrange("设置文字透明度"))
'设置字体大小及名称
textboxshape.textframe.paragraphs(i).textranges(0).fontheight = 20f
textboxshape.textframe.paragraphs(i).textranges(0).latinfont = new textfont("黑体")
'设置文字填充方式
textboxshape.textframe.paragraphs(i).textranges(0).fill.filltype = fillformattype.solid
'通过alpha参数设定不同的颜色透明度(该值的范围为0-255),并应用到文字
textboxshape.textframe.paragraphs(i).textranges(0).fill.solidcolor.color = color.fromargb(alpha, color.white)
alpha = 80
next
'保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013)