How to Apply 3D Effects and Shadows to Shapes
This guide shows how to apply 2D and 3D visual effects to PowerPoint shapes using Aspose.Slides FOSS for Java. Use shape.getEffectFormat() for 2D effects (outer shadow, glow, blur, soft edge) and shape.getThreeDFormat() for 3D appearance (bevel, camera perspective, light rig, material, depth). Both effect systems can be combined on the same shape.
Prerequisites
Add the following dependency to your pom.xml to include the library:
<dependency>
<groupId>org.aspose.slides.foss</groupId>
<artifactId>aspose-slides-foss</artifactId>
<version>1.0.0</version>
</dependency>Add an Outer Drop Shadow
Enable a drop shadow by calling ef.enableOuterShadowEffect() on the shape’s IEffectFormat, then set blur radius, direction, and distance:
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 100, 100, 300, 120
);
shape.addTextFrame("Shadowed Shape");
IEffectFormat ef = shape.getEffectFormat();
ef.enableOuterShadowEffect();
ef.getOuterShadowEffect().setBlurRadius(10); // softness in points
ef.getOuterShadowEffect().setDirection(315); // 315 degrees = upper-left
ef.getOuterShadowEffect().setDistance(8); // offset in points
ef.getOuterShadowEffect().getShadowColor().setColor(
Color.fromArgb(128, 0, 0, 0)
);
prs.save("shadow.pptx", SaveFormat.PPTX);
}Common direction values: 0=right, 45=lower-right, 90=down, 180=left, 270=up, 315=upper-left.
Add a Glow Effect
Enable a glow ring around the shape by calling ef.enableGlowEffect(), then configure the radius and color:
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.ELLIPSE, 150, 100, 250, 250
);
IEffectFormat ef = shape.getEffectFormat();
ef.enableGlowEffect();
ef.getGlowEffect().setRadius(20);
ef.getGlowEffect().getColor().setColor(
Color.fromArgb(255, 255, 215, 0) // gold
);
prs.save("glow.pptx", SaveFormat.PPTX);
}Apply a Gaussian Blur
Apply a Gaussian blur to a shape by calling shape.getEffectFormat().setBlurEffect(radius, grow):
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 100, 100, 350, 180
);
shape.getEffectFormat().setBlurEffect(10, true);
prs.save("blur.pptx", SaveFormat.PPTX);
}grow=true expands the blur region beyond the shape boundary; grow=false clips the blur inside the shape.
Apply a 3D Bevel
Add a raised-edge bevel by configuring shape.getThreeDFormat().getBevelTop() with a BevelPresetType constant, then set width and height:
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 150, 150, 280, 120
);
shape.addTextFrame("3D Button");
IThreeDFormat tdf = shape.getThreeDFormat();
tdf.getBevelTop().setBevelType(BevelPresetType.CIRCLE);
tdf.getBevelTop().setWidth(12);
tdf.getBevelTop().setHeight(6);
prs.save("bevel.pptx", SaveFormat.PPTX);
}BevelPresetType values: CIRCLE, RELAXED_INSET, COOL_SLANT, DIVOT, RIBLET, HARD_EDGE, SLOPE, CONVEX
3D Bevel with Camera and Light Rig
Combine a bevel with a camera projection and light rig to produce a fully three-dimensional metal appearance. Use tdf.getCamera().setCameraType(), tdf.getLightRig().setLightType(), tdf.getLightRig().setDirection(), and tdf.setMaterial():
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 150, 150, 280, 120
);
shape.addTextFrame("Metal Button");
IThreeDFormat tdf = shape.getThreeDFormat();
tdf.getBevelTop().setBevelType(BevelPresetType.CIRCLE);
tdf.getBevelTop().setWidth(10);
tdf.getBevelTop().setHeight(5);
tdf.getCamera().setCameraType(CameraPresetType.PERSPECTIVE_ABOVE);
tdf.getLightRig().setLightType(LightRigPresetType.BALANCED);
tdf.getLightRig().setDirection(LightingDirection.TOP);
tdf.setMaterial(MaterialPresetType.METAL);
tdf.setDepth(20);
prs.save("3d-metal.pptx", SaveFormat.PPTX);
}Combine Shadow and 3D Bevel
Both effect systems can be active simultaneously on the same shape:
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.ROUND_CORNER_RECTANGLE, 150, 150, 320, 130
);
shape.addTextFrame("Premium Card");
// Solid fill
shape.getFillFormat().setFillType(FillType.SOLID);
shape.getFillFormat().getSolidFillColor().setColor(
Color.fromArgb(255, 30, 80, 180)
);
// 3D bevel
IThreeDFormat tdf = shape.getThreeDFormat();
tdf.getBevelTop().setBevelType(BevelPresetType.CIRCLE);
tdf.getBevelTop().setWidth(8);
tdf.getCamera().setCameraType(CameraPresetType.PERSPECTIVE_ABOVE);
tdf.setMaterial(MaterialPresetType.PLASTIC);
// Drop shadow
IEffectFormat ef = shape.getEffectFormat();
ef.enableOuterShadowEffect();
ef.getOuterShadowEffect().setBlurRadius(12);
ef.getOuterShadowEffect().setDirection(270);
ef.getOuterShadowEffect().setDistance(6);
ef.getOuterShadowEffect().getShadowColor().setColor(
Color.fromArgb(80, 0, 0, 0)
);
prs.save("premium-card.pptx", SaveFormat.PPTX);
}Check and Remove Effects
Check whether a shape has active effects using IEffectFormat.isNoEffects(), then disable individual effects with disableOuterShadowEffect() or disableGlowEffect():
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.IEffectFormat;
import org.aspose.slides.foss.IThreeDFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.LightRigPresetType;
import org.aspose.slides.foss.LightingDirection;
import org.aspose.slides.foss.MaterialPresetType;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.Color;
try (Presentation prs = new Presentation()) {
ISlideCollection slides = prs.getSlides();
ISlide slide = slides.get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 100, 100, 200, 100
);
IEffectFormat ef = shape.getEffectFormat();
ef.enableOuterShadowEffect();
ef.enableGlowEffect();
System.out.println("Has effects: " + !ef.isNoEffects()); // true
ef.disableOuterShadowEffect();
ef.disableGlowEffect();
System.out.println("Has effects: " + !ef.isNoEffects()); // false
}