How to Apply 3D Effects and Shadows to Shapes
Aspose.Slides FOSS provides two independent effect systems on every shape:
shape.getEffectFormat(): 2D visual effects: outer shadow, glow, blur, soft edgeshape.getThreeDFormat(): 3D appearance: bevel, camera perspective, light rig, material, depth
Both systems can be combined on the same shape.
Prerequisites
<dependency>
<groupId>org.aspose.slides.foss</groupId>
<artifactId>aspose-slides-foss</artifactId>
<version>1.0.0</version>
</dependency>Add an Outer Drop Shadow
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
import org.aspose.slides.foss.*;
try (Presentation prs = new Presentation()) {
IAutoShape shape = prs.getSlides().get(0).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
}