How to Apply 3D Effects and Shadows to Shapes
Aspose.Slides FOSS provides two independent effect systems on every shape:
shape.effect_format(): 2D visual effects: outer shadow, glow, blur, soft edgeshape.three_d_format(): 3D appearance: bevel, camera perspective, light rig, material, depth
Both systems can be combined on the same shape.
Prerequisites
git clone https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
cd Aspose.Slides-FOSS-for-Cpp && mkdir build && cd build
cmake .. && cmake --build .Add an Outer Drop Shadow
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 100, 100, 300, 120);
shape.add_text_frame("Shadowed Shape");
auto& ef = shape.effect_format();
ef.enable_outer_shadow_effect();
ef.outer_shadow_effect().set_blur_radius(10); // softness in points
ef.outer_shadow_effect().set_direction(315); // 315 deg = upper-left
ef.outer_shadow_effect().set_distance(8); // offset in points
ef.outer_shadow_effect().shadow_color().set_color(
asf::Color::from_argb(128, 0, 0, 0));
prs.save("shadow.pptx", asf::SaveFormat::PPTX);
return 0;
}Common direction values: 0=right, 45=lower-right, 90=down, 180=left, 270=up, 315=upper-left.
Add a Glow Effect
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::ELLIPSE, 150, 100, 250, 250);
auto& ef = shape.effect_format();
ef.enable_glow_effect();
ef.glow_effect().set_radius(20);
ef.glow_effect().color().set_color(asf::Color::gold());
prs.save("glow.pptx", asf::SaveFormat::PPTX);
return 0;
}Apply a Gaussian Blur
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 100, 100, 350, 180);
shape.effect_format().set_blur_effect(10, true);
prs.save("blur.pptx", asf::SaveFormat::PPTX);
return 0;
}grow=true expands the blur region beyond the shape boundary; grow=false clips the blur inside the shape.
Apply a 3D Bevel
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 150, 150, 280, 120);
shape.add_text_frame("3D Button");
auto& tdf = shape.three_d_format();
tdf.bevel_top().set_bevel_type(asf::BevelPresetType::CIRCLE);
tdf.bevel_top().set_width(12);
tdf.bevel_top().set_height(6);
prs.save("bevel.pptx", asf::SaveFormat::PPTX);
return 0;
}BevelPresetType values: CIRCLE, RELAXED_INSET, COOL_SLANT, DIVOT, RIBLET, HARD_EDGE, SLOPE, CONVEX
3D Bevel with Camera and Light Rig
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 150, 150, 280, 120);
shape.add_text_frame("Metal Button");
auto& tdf = shape.three_d_format();
tdf.bevel_top().set_bevel_type(asf::BevelPresetType::CIRCLE);
tdf.bevel_top().set_width(10);
tdf.bevel_top().set_height(5);
tdf.camera().set_camera_type(asf::CameraPresetType::PERSPECTIVE_ABOVE);
tdf.light_rig().set_light_type(asf::LightRigPresetType::BALANCED);
tdf.light_rig().set_direction(asf::LightingDirection::TOP);
tdf.set_material(asf::MaterialPresetType::METAL);
tdf.set_depth(20);
prs.save("3d-metal.pptx", asf::SaveFormat::PPTX);
return 0;
}Combine Shadow and 3D Bevel
Both effect systems can be active simultaneously on the same shape:
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::ROUND_CORNER_RECTANGLE, 150, 150, 320, 130);
shape.add_text_frame("Premium Card");
// Solid fill
shape.fill_format().set_fill_type(asf::FillType::SOLID);
shape.fill_format().solid_fill_color().set_color(
asf::Color::from_argb(255, 30, 80, 180));
// 3D bevel
auto& tdf = shape.three_d_format();
tdf.bevel_top().set_bevel_type(asf::BevelPresetType::CIRCLE);
tdf.bevel_top().set_width(8);
tdf.camera().set_camera_type(asf::CameraPresetType::PERSPECTIVE_ABOVE);
tdf.set_material(asf::MaterialPresetType::PLASTIC);
// Drop shadow
auto& ef = shape.effect_format();
ef.enable_outer_shadow_effect();
ef.outer_shadow_effect().set_blur_radius(12);
ef.outer_shadow_effect().set_direction(270);
ef.outer_shadow_effect().set_distance(6);
ef.outer_shadow_effect().shadow_color().set_color(
asf::Color::from_argb(80, 0, 0, 0));
prs.save("premium-card.pptx", asf::SaveFormat::PPTX);
return 0;
}Check and Remove Effects
#include <Aspose/Slides/Foss/presentation.h>
#include <iostream>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& shape = prs.slides()[0].shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 100, 100, 200, 100);
auto& ef = shape.effect_format();
ef.enable_outer_shadow_effect();
ef.enable_glow_effect();
std::cout << "Has effects: " << !ef.is_no_effects() << "\n"; // 1
ef.disable_outer_shadow_effect();
ef.disable_glow_effect();
std::cout << "Has effects: " << !ef.is_no_effects() << "\n"; // 0
return 0;
}