在 .NET 簡報中套用形狀效果
簡介
雖然 PowerPoint 中的效果可用於讓形狀凸顯,但它們不同於 填色 或輪廓。使用 PowerPoint 效果,您可以在形狀上建立逼真的反射、擴散形狀的發光等。

PowerPoint 提供六種可套用於形狀的效果。您可以對形狀套用一個或多個效果。
某些效果組合看起來比其他組合更佳。因此,PowerPoint 在 Preset 下提供選項。Preset 選項本質上是已知的好看組合,包含兩個或多個效果。透過選取預設,您不必浪費時間測試或組合不同的效果來尋找理想的組合。
Aspose.Slides 在 EffectFormat 類別提供屬性與方法,讓您能將相同的效果套用到 PowerPoint 簡報中的形狀。
套用陰影效果
Aspose.Slides for .NET 支援形狀的外部與內部陰影。您可以自訂其顏色、方向、距離與模糊半徑,以符合簡報的設計。
套用外部陰影
使用外部陰影可使卡片或面板在投影片背景上凸顯。陰影會超出形狀邊緣,營造形狀翹起於投影片之上的感覺。調整其顏色、方向、距離與模糊半徑,以符合範本的光源與樣式。
此 C# 程式碼示範如何將 外部陰影效果 套用到矩形:
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.EffectFormat.EnableOuterShadowEffect();
shape.EffectFormat.OuterShadowEffect.ShadowColor.Color = Color.DarkGray;
shape.EffectFormat.OuterShadowEffect.Distance = 10;
shape.EffectFormat.OuterShadowEffect.Direction = 45;
presentation.Save("shadow_effect.pptx", SaveFormat.Pptx);

在形狀旋轉時控制陰影方向
預設情況下,RotateShadowWithShape 為 true,因此陰影會隨形狀旋轉。若要使不同旋轉角度的形狀看起來光源方向相同,請將此屬性設為 false,並將它們的陰影設定為相同的 Direction。
範例建立兩個箭頭,灰色陰影向右偏移 (Direction = 0)。接著複製投影片並將兩個箭頭順時針旋轉 90°。
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var before = presentation.Slides[0];
var left = before.Shapes.AddAutoShape(ShapeType.RightArrow, 55, 130, 110, 60);
left.FillFormat.FillType = FillType.Solid;
left.FillFormat.SolidFillColor.Color = Color.SteelBlue;
left.LineFormat.FillFormat.FillType = FillType.NoFill;
left.EffectFormat.EnableOuterShadowEffect();
var shadow = left.EffectFormat.OuterShadowEffect;
shadow.ShadowColor.Color = Color.Gray;
shadow.Direction = 0;
shadow.Distance = 42;
shadow.BlurRadius = 0;
shadow.RotateShadowWithShape = true;
var right = before.Shapes.AddClone(left);
right.X = 395;
right.EffectFormat.OuterShadowEffect.RotateShadowWithShape = false;
var after = presentation.Slides.AddClone(before);
foreach (var arrow in after.Shapes)
arrow.Rotation = 90;
presentation.Save("arrow_shadows.pptx", SaveFormat.Pptx);
在第二張投影片中,左側箭頭的陰影向下投射,而右側箭頭的陰影仍向右。兩個陰影的設定方向均維持 0°。

套用內部陰影
在重現範本的視覺樣式時,使用內部陰影可為卡片或面板營造凹陷的外觀。外部陰影延伸至形狀外部,使其看起來凸起;而內部陰影則在其邊緣內側著色。
呼叫 EnableInnerShadowEffect,然後設定 InnerShadowEffect。較大的數值會產生較柔和的邊緣。
此 C# 範例建立一個淡藍色卡片,帶有深灰色內部陰影,並將其儲存為 PPTX 檔案:
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 200, 100);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.LightBlue;
shape.LineFormat.FillFormat.FillType = FillType.NoFill;
shape.EffectFormat.EnableInnerShadowEffect();
var shadow = shape.EffectFormat.InnerShadowEffect;
shadow.ShadowColor.Color = Color.DimGray;
shadow.Direction = 225;
shadow.Distance = 7;
shadow.BlurRadius = 6;
presentation.Save("inner_shadow_effect.pptx", SaveFormat.Pptx);

若要移除內部陰影,請對形狀的 effect format 呼叫 DisableInnerShadowEffect。
套用、變更與移除預設陰影
呼叫 EnablePresetShadowEffect 並將 Preset 設為具名的 PresetShadowType。若要切換樣式,只需在同一形狀上變更 preset。呼叫 DisablePresetShadowEffect 可在保留填色與輪廓的同時移除陰影。
此範例在每個階段保留矩形的副本。兩個陰影皆偏移 10 點。225° 的方向將第一個陰影放置於矩形的左上方,45° 的方向則將第二個陰影放於右下方。
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(800, 120, SlideSizeScaleType.DoNotScale);
var shapes = presentation.Slides[0].Shapes;
var shape = shapes.AddAutoShape(ShapeType.Rectangle, 15, 30, 170, 60);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.SteelBlue;
shape.LineFormat.FillFormat.FillType = FillType.Solid;
shape.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;
shape.TextFrame.Text = "No shadow";
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 14;
shapes.AddClone(shape);
shape.X += 200;
shape.EffectFormat.EnablePresetShadowEffect();
var shadow = shape.EffectFormat.PresetShadowEffect;
shadow.Preset = PresetShadowType.TopLeftDropShadow;
shadow.Distance = 10;
shadow.Direction = 225;
shape.TextFrame.Text = shadow.Preset.ToString();
shapes.AddClone(shape);
shape.X += 200;
shadow.Preset = PresetShadowType.BottomRightDropShadow;
shadow.Direction = 45;
shape.TextFrame.Text = shadow.Preset.ToString();
shapes.AddClone(shape);
shape.X += 200;
shape.EffectFormat.DisablePresetShadowEffect();
shape.TextFrame.Text = "No shadow";
presentation.Save("preset_shadows.pptx", SaveFormat.Pptx);
| 原始 | 第一預設 | 第二預設 | 移除後 |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
套用反射效果
要在 Aspose.Slides for .NET 中套用反射效果,您可以為形狀新增鏡像般的反射,調整距離、透明度與大小等參數。此效果可提升簡報的美感,讓形狀更顯精緻與專業。透過簡單程式碼即可快速在多個元素間套用,保持設計一致性。
此 C# 程式碼示範如何將 反射效果 套用到形狀:
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.EffectFormat.EnableReflectionEffect();
shape.EffectFormat.ReflectionEffect.RectangleAlign = RectangleAlignment.Bottom;
shape.EffectFormat.ReflectionEffect.Direction = 90;
shape.EffectFormat.ReflectionEffect.Distance = 40;
shape.EffectFormat.ReflectionEffect.BlurRadius = 2;
presentation.Save("reflection_effect.pptx", SaveFormat.Pptx);

控制反射淡化
StartPosAlpha 與 EndPosAlpha 指定 淡化開始與結束的位置,以相對於梯度距離的百分比表示。StartReflectionOpacity 與 EndReflectionOpacity 指定 在這些位置的透明度。例如,位置為 0% 與 50%,不透明度為 80% 與 0% 時,反射會在 80% 不透明度開始,於梯度中點完全透明。
Direction 設定反射相對於形狀的偏移角度。FadeDirection 設定透明度變化的角度。範例將五個反射皆放置於矩形下方,且保持比例、距離與模糊相同。
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(720, 200, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];
var settings = new (int StartPos, int EndPos, int StartOpacity, int EndOpacity, int FadeAngle)[]
{
(0, 100, 80, 0, 90),
(50, 100, 80, 0, 90),
(0, 50, 80, 0, 90),
(0, 100, 50, 25, 90),
(0, 100, 80, 0, 0)
};
for (int i = 0; i < settings.Length; i++)
{
var fade = settings[i];
var x = 16 + 144 * i;
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, 48, 112, 62);
shape.EffectFormat.EnableReflectionEffect();
var reflection = shape.EffectFormat.ReflectionEffect;
reflection.RectangleAlign = RectangleAlignment.Bottom;
reflection.Direction = 90;
reflection.Distance = 6;
reflection.ScaleHorizontal = 100;
reflection.ScaleVertical = -100;
reflection.BlurRadius = 0;
reflection.StartPosAlpha = fade.StartPos;
reflection.EndPosAlpha = fade.EndPos;
reflection.StartReflectionOpacity = fade.StartOpacity;
reflection.EndReflectionOpacity = fade.EndOpacity;
reflection.FadeDirection = fade.FadeAngle;
}
presentation.Save("reflection_fade.pptx", SaveFormat.Pptx);

說明從左至右的五種設定:
- 基準。 透明度從 80% 下降至 0%,覆蓋整個反射高度。
- 較晚開始。 上半部保持 80% 透明度。淡化在中間開始。
- 較早結束。 反射在中間達到 0% 透明度,使下半部透明。
- 不同透明度。 淡化遍佈整個高度,起始於 50% 透明度,結束於 25%,因此底部邊緣仍可見。
- 水平淡化。 將最右側矩形與最左側的基準比較。兩個反射皆向下偏移 90°。將淡化角度從 90° 改為 0°,梯度會向右。
套用發光效果
要在 Aspose.Slides for .NET 中套用發光效果,您可以在形狀周圍加入柔和、發光的光暈,調整顏色與大小等屬性。此效果有助於讓形狀凸顯,為簡報增添吸睛的視覺元素。只需少量程式碼即可實作,提升投影片的整體觀感。
此 C# 程式碼示範如何將 glow effect 套用到形狀:
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.EffectFormat.EnableGlowEffect();
shape.EffectFormat.GlowEffect.Color.Color = Color.Magenta;
shape.EffectFormat.GlowEffect.Radius = 15;
presentation.Save("glow_effect.pptx", SaveFormat.Pptx);

套用柔化邊緣效果
要在 Aspose.Slides for .NET 中套用柔化邊緣效果,您可以為形狀的邊緣建立平滑、模糊的過渡。此效果能為設計增添更細膩、精緻的外觀,適合需要柔和外觀的設計。您可輕鬆調整半徑等參數,以在簡報中的各種形狀上達成理想效果。
此 C# 程式碼示範如何將 soft edges 套用到形狀:
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 150);
shape.EffectFormat.EnableSoftEdgeEffect();
shape.EffectFormat.SoftEdgeEffect.Radius = 8;
presentation.Save("soft_edges_effect.pptx", SaveFormat.Pptx);

套用模糊效果
使用形狀模糊可在保持形狀可編輯的同時柔化其填色與輪廓。呼叫 SetBlurEffect 於形狀的 effect format。半徑以點 (1/72 吋) 為單位:使用非負值,值越大模糊程度越強。半徑為 0 時外觀不變。
Grow 設定控制效果的可見範圍。false 時,模糊限制在原始繪製範圍內,包括輪廓;true 時,模糊可延伸超出該範圍。兩種設定皆不會改變形狀的位置或尺寸。
下表比較使用相同填色、輪廓與形狀尺寸的情形。上排使用 grow = false;下排使用 grow = true。

此 C# 範例建立一個橙色矩形,搭配深藍色輪廓,先套用 5 點模糊,然後再呼叫 SetBlurEffect 將模糊升級為 15 點,並分別儲存兩個模糊狀態。最後呼叫 DisableBlurEffect 並儲存未模糊的形狀。
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 100, 80, 160, 100);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.Orange;
shape.LineFormat.FillFormat.FillType = FillType.Solid;
shape.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;
shape.LineFormat.Width = 8;
shape.EffectFormat.SetBlurEffect(5, false);
presentation.Save("shape_blur_5.pptx", SaveFormat.Pptx);
shape.EffectFormat.SetBlurEffect(15, true);
presentation.Save("shape_blur_15.pptx", SaveFormat.Pptx);
shape.EffectFormat.DisableBlurEffect();
presentation.Save("shape_blur_removed.pptx", SaveFormat.Pptx);
形狀模糊同時影響填色與輪廓。柔化邊緣效果會淡化形狀的邊緣,而陰影模糊僅軟化陰影。圖像轉換效果作用於圖像內容;本例直接對形狀的 effect format 套用模糊,未將形狀轉換為圖像。
套用填充覆蓋
形狀的 FillFormat 定義其基本填色。呼叫 EnableFillOverlayEffect 可加入第二層填色。使用 FillOverlayEffect 的 FillFormat 來設定覆蓋顏色。其 Blend 屬性接受 FillBlendMode 的值,以控制兩層填色的混合方式。
範例保留原始藍色矩形作為比較。將實心珊瑚色覆蓋套用到副本,接著在下一個副本只變更混合模式。最後一個副本呼叫 DisableFillOverlayEffect 以移除覆蓋,恢復基礎填色。
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using var presentation = new Presentation();
var shapes = presentation.Slides[0].Shapes;
var original = shapes.AddAutoShape(ShapeType.Rectangle, 10, 15, 140, 90);
original.FillFormat.FillType = FillType.Solid;
original.FillFormat.SolidFillColor.Color = Color.FromArgb(80, 140, 200);
original.LineFormat.FillFormat.FillType = FillType.NoFill;
var multiply = shapes.AddClone(original);
multiply.X = 170;
multiply.EffectFormat.EnableFillOverlayEffect();
var overlay = multiply.EffectFormat.FillOverlayEffect;
overlay.FillFormat.FillType = FillType.Solid;
overlay.FillFormat.SolidFillColor.Color = Color.FromArgb(200, 100, 80);
overlay.Blend = FillBlendMode.Multiply;
var screen = shapes.AddClone(multiply);
screen.X = 330;
screen.EffectFormat.FillOverlayEffect.Blend = FillBlendMode.Screen;
var removed = shapes.AddClone(multiply);
removed.X = 490;
removed.EffectFormat.DisableFillOverlayEffect();
presentation.Save("fill_overlay.pptx", SaveFormat.Pptx);
在 PowerPoint 中,Multiply 會使藍色矩形變暗,Screen 會使其變亮。移除覆蓋後,最後的矩形與原始相同。

常見問題
我可以對同一形狀套用多個效果嗎?
是的,您可以在單一形狀上結合陰影、反射、發光等不同效果,以產生更具動感的外觀。
我可以對哪些形狀套用效果?
您可以對各種形狀套用效果,包括自動圖形、圖表、表格、圖片、SmartArt 物件、OLE 物件等。
我可以對群組形狀套用效果嗎?
可以,您可以對群組形狀套用效果,該效果會套用至整個群組。



