在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)