Làm việc với Hiệu ứng 3D và Hiệu ứng hình ảnh — Aspose.Slides FOSS cho .NET
Aspose.Slides FOSS for .NET cung cấp hai hệ thống hiệu ứng riêng biệt có thể truy cập trên mọi hình dạng:
EffectFormat(shape.EffectFormat): hiệu ứng hình ảnh 2D: shadow, glow, soft edge, blur, reflectionThreeDFormat(shape.ThreeDFormat): 3D appearance: bevel, camera projection, light rig, material, extrusion depth
Cả hai đều được duy trì qua các chu kỳ lưu/tải lại.
Hiệu ứng trực quan (EffectFormat)
Bóng đổ ngoài
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 Text");
var ef = shape.EffectFormat;
ef.EnableOuterShadowEffect();
ef.OuterShadowEffect.BlurRadius = 10; // softness in points
ef.OuterShadowEffect.Direction = 315; // angle: 315 = upper-left cast
ef.OuterShadowEffect.Distance = 8; // offset in points
ef.OuterShadowEffect.ShadowColor.Color = Color.FromArgb(128, 0, 0, 0); // semi-transparent black
prs.Save("shadow.pptx", SaveFormat.Pptx);Các giá trị Direction chung: 0 = phải, 45 = dưới-phải, 90 = xuống, 270 = lên, 315 = trên-trái.
Hiệu ứng phát sáng
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, 200, 200);
var ef = shape.EffectFormat;
ef.EnableGlowEffect();
ef.GlowEffect.Radius = 15;
ef.GlowEffect.Color.Color = Color.Gold;
prs.Save("glow.pptx", SaveFormat.Pptx);Viền mềm (Viền mờ)
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);
var ef = shape.EffectFormat;
ef.EnableSoftEdgeEffect();
ef.SoftEdgeEffect.Radius = 12; // feather radius in points
prs.Save("soft-edge.pptx", SaveFormat.Pptx);Blur
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(8, true);
prs.Save("blur.pptx", SaveFormat.Pptx);Kiểm tra và Xóa hiệu ứng
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Định dạng 3D (ThreeDFormat)
Hiệu ứng Bo góc
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, 250, 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);Các giá trị BevelPresetType: Circle, RelaxedInset, CoolSlant, Divot, Riblet, HardEdge, Slope, Convex
Cài đặt trước máy ảnh
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, 250, 120);
var tdf = shape.ThreeDFormat;
tdf.BevelTop.BevelType = BevelPresetType.Circle;
tdf.BevelTop.Width = 10;
tdf.Camera.CameraType = CameraPresetType.PerspectiveAbove;
prs.Save("camera.pptx", SaveFormat.Pptx);Bộ rig ánh sáng và Vật liệu
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, 250, 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);Các giá trị MaterialPresetType: Standard, Warm, Cool, Plastic, Metal, Matte, WireFrame
Kết hợp hiệu ứng 2D và 3D
Bạn có thể áp dụng cả EffectFormat và ThreeDFormat cho cùng một hình dạng:
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, 300, 120);
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);