Como aplicar efeitos e sombras 3D para formas
Este guia mostra como aplicar efeitos visuais 2D e 3D para formas do PowerPoint usando Aspose.Slides FOSS para .NET. Use shape.EffectFormat para efeitos 2D, tais como sombra externa, brilho, desfoque e borda macia. shape.ThreeDFormat Para o aspecto 3D, incluindo bevel, perspectiva da câmara, iluminação, material e profundidade. Ambos os sistemas de efeitos podem ser combinados na mesma forma.
Precondições
Adicione a seguinte referência de pacote ao seu projeto executando o comando dotnet CLI install:
aspose-slides-foss/slides is not yet published — build from source until it ships. See the project README for build instructions.Adicionar uma sombra de gota exterior
Chama-me . shape.EffectFormat.EnableOuterShadowEffect() para ativar a sombra externa, em seguida configurar OuterShadowEffect.BlurRadius, Direction, e Distance para controlar a sua aparência:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Rectangle, 100, 100, 300, 120
);
shape.AddTextFrame("Shadowed Shape");
var ef = shape.EffectFormat;
ef.EnableOuterShadowEffect();
ef.OuterShadowEffect.BlurRadius = 10; // softness in points
ef.OuterShadowEffect.Direction = 315; // 315 degrees = upper-left
ef.OuterShadowEffect.Distance = 8; // offset in points
ef.OuterShadowEffect.ShadowColor.Color = Color.FromArgb(128, 0, 0, 0);
prs.Save("shadow.pptx", SaveFormat.Pptx);Comum Direction valores de: 0- Certo, não., 45= inferior-direita, 90= para baixo, 180= à esquerda, 270- Para cima., 315- A esquerda.
Adicionar um efeito de brilho
Chama-me . shape.EffectFormat.EnableGlowEffect() para ativar o brilho, em seguida, definir GlowEffect.Radius e a) GlowEffect.Color.Color para controlar a sua propagação e cor:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Ellipse, 150, 100, 250, 250
);
var ef = shape.EffectFormat;
ef.EnableGlowEffect();
ef.GlowEffect.Radius = 20;
ef.GlowEffect.Color.Color = Color.Gold;
prs.Save("glow.pptx", SaveFormat.Pptx);Aplicar um desfoque gaussiano
Aplicar um desfoque gaussiano a uma forma chamando shape.EffectFormat.SetBlurEffect(radius, grow) onde: radius Controla a difusão da mancha em pontos:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Rectangle, 100, 100, 350, 180
);
shape.EffectFormat.SetBlurEffect(radius: 10, grow: true);
prs.Save("blur.pptx", SaveFormat.Pptx);grow: true expande a região de desfocamento para além do limite da forma; grow: false Clip a mancha dentro da forma.
Aplicar um Bevel 3D
Acessos shape.ThreeDFormat.BevelTop e definido BevelType, Width, e Height Para adicionar uma borda 3D elevada à volta da forma:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Rectangle, 150, 150, 280, 120
);
shape.AddTextFrame("3D Button");
var tdf = shape.ThreeDFormat;
tdf.BevelTop.BevelType = BevelPresetType.Circle;
tdf.BevelTop.Width = 12;
tdf.BevelTop.Height = 6;
prs.Save("bevel.pptx", SaveFormat.Pptx);BevelPresetType valores de: Circle, RelaxedInset, CoolSlant, Divot, Riblet, HardEdge, Slope, Convex
3D Bevel with Camera and Light Rig
Set (s) ThreeDFormat.Camera.CameraType, LightRig.LightType, Material, e Depth Juntos, para obter uma aparência 3D totalmente representada:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Rectangle, 150, 150, 280, 120
);
shape.AddTextFrame("Metal Button");
var tdf = shape.ThreeDFormat;
tdf.BevelTop.BevelType = BevelPresetType.Circle;
tdf.BevelTop.Width = 10;
tdf.BevelTop.Height = 5;
tdf.Camera.CameraType = CameraPresetType.PerspectiveAbove;
tdf.LightRig.LightType = LightRigPresetType.Balanced;
tdf.LightRig.Direction = LightingDirection.Top;
tdf.Material = MaterialPresetType.Metal;
tdf.Depth = 20;
prs.Save("3d-metal.pptx", SaveFormat.Pptx);Combina sombra e 3D Bevel
Os dois sistemas de efeito podem ser ativados simultaneamente na mesma forma:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.RoundCornerRectangle, 150, 150, 320, 130
);
shape.AddTextFrame("Premium Card");
// Solid fill
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.FromArgb(255, 30, 80, 180);
// 3D bevel
var tdf = shape.ThreeDFormat;
tdf.BevelTop.BevelType = BevelPresetType.Circle;
tdf.BevelTop.Width = 8;
tdf.Camera.CameraType = CameraPresetType.PerspectiveAbove;
tdf.Material = MaterialPresetType.Plastic;
// Drop shadow
var ef = shape.EffectFormat;
ef.EnableOuterShadowEffect();
ef.OuterShadowEffect.BlurRadius = 12;
ef.OuterShadowEffect.Direction = 270;
ef.OuterShadowEffect.Distance = 6;
ef.OuterShadowEffect.ShadowColor.Color = Color.FromArgb(80, 0, 0, 0);
prs.Save("premium-card.pptx", SaveFormat.Pptx);Verificar e remover efeitos
Utilização: EffectFormat.IsNoEffects para detectar se algum efeito está ativo, e chamar a atenção da DisableOuterShadowEffect() ou a) DisableGlowEffect() para eliminar efeitos individuais:
using Aspose.Slides.Foss;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(
ShapeType.Rectangle, 100, 100, 200, 100
);
var ef = shape.EffectFormat;
ef.EnableOuterShadowEffect();
ef.EnableGlowEffect();
Console.WriteLine($"Has effects: {!ef.IsNoEffects}"); // True
ef.DisableOuterShadowEffect();
ef.DisableGlowEffect();
Console.WriteLine($"Has effects: {!ef.IsNoEffects}"); // False