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

若要移除内部阴影,请在形状的 EffectFormat 上调用 DisableInnerShadowEffect。
应用、更改和删除预设阴影
调用 EnablePresetShadowEffect 并将 Preset 设置为指定的 PresetShadowType。要切换样式,只需在同一形状上更改预设。调用 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);
| Original | First preset | Second preset | After removal |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
应用反射效果
要在 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);

应用发光效果
要在 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.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# 代码演示如何将 柔化边缘 应用于形状:
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);

应用模糊效果
使用形状模糊可在保持形状可编辑的前提下柔化其填充和轮廓。调用形状的 EffectFormat 上的 SetBlurEffect 即可。半径以点为单位(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);
形状模糊同时影响填充和轮廓。柔化边缘效果仅淡化形状边缘,而阴影模糊仅软化阴影本身。图像变换效果作用于图像内容;本示例直接在形状的 EffectFormat 上应用模糊,无需将形状转换为图像。
应用填充覆盖
形状的 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 对象等。
我可以对组合形状应用效果吗?
可以,效果将应用于整个组合。



