在PPT中,形狀是非常重要的元素。3-D形狀,立體多元,給人耳目一新的感覺。在幻燈片中添加3-D效果形狀,必然會為PPT的整體效果增色不少。為形狀設定三維格式時,可設定棱台,輪廓線,表面效果等。
本篇文章,旨在介紹在使用免費的Spire.Presentation,獨立建立Powerpoint文檔,添加形狀,并設定三維效果。感興趣的朋友,可以從E-iceblue官網下載下傳免費的Spire.Presentation。下載下傳完成後,請将bin檔案夾的.dll添加作為引用。友情提示:使用Spire.Presentation可獨立建立powerpoint文檔。
需要添加的命名空間:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
步驟詳叙:
步驟一:建立PPT文檔。
Presentation presentation = new Presentation();
步驟二:添加形狀,設定其位置,大小并填充顔色。
IAutoShape shape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.RightArrow, new RectangleF(150, 150, 150, 150));
shape1.Fill.FillType = FillFormatType.Solid;
shape1.Fill.SolidColor.KnownColor = KnownColors.RoyalBlue;
步驟三:為該形狀設定三維效果。
ShapeThreeD Demo1 = shape1.ThreeD.ShapeThreeD;
//設定表面效果
Demo1.PresetMaterial = PresetMaterialType.Matte;
//設定棱台類型,高度和寬度
Demo1.TopBevel.PresetType = BevelPresetType.ArtDeco;
Demo1.TopBevel.Height = 4;
Demo1.TopBevel.Width = 12;
//設定輪廓線類型,顔色,寬度
Demo1.BevelColorMode = BevelColorType.Contour;
Demo1.ContourColor.KnownColor = KnownColors.LightBlue;
Demo1.ContourWidth = 3.5;
步驟四:再添加一個形狀作為對照。
IAutoShape shape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Pentagon, new RectangleF(400, 150, 150, 150));
shape2.Fill.FillType = FillFormatType.Solid;
shape2.Fill.SolidColor.KnownColor = KnownColors.LawnGreen;
ShapeThreeD Demo2 = shape2.ThreeD.ShapeThreeD;
Demo2.PresetMaterial = PresetMaterialType.SoftEdge;
Demo2.TopBevel.PresetType = BevelPresetType.SoftRound;
Demo2.TopBevel.Height = 12;
Demo2.TopBevel.Width = 12;
Demo2.BevelColorMode = BevelColorType.Contour;
Demo2.ContourColor.KnownColor = KnownColors.LawnGreen;
Demo2.ContourWidth = 5;
步驟五:儲存文檔為.pptx,啟動檢視效果。
presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
效果截圖:
完整代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
IAutoShape shape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.RightArrow, new RectangleF(150, 150, 150, 150));
shape1.Fill.FillType = FillFormatType.Solid;
shape1.Fill.SolidColor.KnownColor = KnownColors.RoyalBlue;
ShapeThreeD Demo1 = shape1.ThreeD.ShapeThreeD;
Demo1.PresetMaterial = PresetMaterialType.Matte;
Demo1.TopBevel.PresetType = BevelPresetType.ArtDeco;
Demo1.TopBevel.Height = 4;
Demo1.TopBevel.Width = 12;
Demo1.BevelColorMode = BevelColorType.Contour;
Demo1.ContourColor.KnownColor = KnownColors.LightBlue;
Demo1.ContourWidth = 3.5;
IAutoShape shape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Pentagon, new RectangleF(400, 150, 150, 150));
shape2.Fill.FillType = FillFormatType.Solid;
shape2.Fill.SolidColor.KnownColor = KnownColors.LawnGreen;
ShapeThreeD Demo2 = shape2.ThreeD.ShapeThreeD;
Demo2.PresetMaterial = PresetMaterialType.SoftEdge;
Demo2.TopBevel.PresetType = BevelPresetType.SoftRound;
Demo2.TopBevel.Height = 12;
Demo2.TopBevel.Width = 12;
Demo2.BevelColorMode = BevelColorType.Contour;
Demo2.ContourColor.KnownColor = KnownColors.LawnGreen;
Demo2.ContourWidth = 5;
presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
}
}
}
感謝閱讀,如有疑問,請留言。