Working with 3D Effects and Visual Effects — Aspose.Slides FOSS for Java
Aspose.Slides FOSS for Java provides two separate effect systems accessible on every shape:
EffectFormat(shape.getEffectFormat()): 2D visual effects: shadow, glow, soft edge, blur, reflectionThreeDFormat(shape.getThreeDFormat()): 3D appearance: bevel, camera projection, light rig, material, extrusion depth
Both persist through save/reload cycles.
Visual Effects (EffectFormat)
Outer Drop Shadow
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.Color;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 100, 100, 300, 120);
shape.addTextFrame("Shadowed Text");
var ef = shape.getEffectFormat();
ef.enableOuterShadowEffect();
ef.getOuterShadowEffect().setBlurRadius(10); // softness in points
ef.getOuterShadowEffect().setDirection(315); // angle: 315 = upper-left cast
ef.getOuterShadowEffect().setDistance(8); // offset in points
ef.getOuterShadowEffect().getShadowColor().setColor(Color.fromArgb(128, 0, 0, 0)); // semi-transparent black
prs.save("shadow.pptx", SaveFormat.PPTX);
}Common direction values: 0 = right, 45 = lower-right, 90 = down, 270 = up, 315 = upper-left.
Glow Effect
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.Color;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.ELLIPSE, 150, 100, 200, 200);
var ef = shape.getEffectFormat();
ef.enableGlowEffect();
ef.getGlowEffect().setRadius(15);
ef.getGlowEffect().getColor().setColor(Color.fromArgb(255, 255, 215, 0)); // gold
prs.save("glow.pptx", SaveFormat.PPTX);
}Soft Edge (Feathered Border)
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 100, 100, 350, 180);
var ef = shape.getEffectFormat();
ef.enableSoftEdgeEffect();
ef.getSoftEdgeEffect().setRadius(12); // feather radius in points
prs.save("soft-edge.pptx", SaveFormat.PPTX);
}Blur
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 100, 100, 350, 180);
shape.getEffectFormat().setBlurEffect(8, true);
prs.save("blur.pptx", SaveFormat.PPTX);
}Checking and Removing Effects
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 100, 100, 200, 100);
var 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
}3D Formatting (ThreeDFormat)
Bevel Effect
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 150, 150, 250, 120);
shape.addTextFrame("3D Button");
var 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
Camera Preset
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.CameraPresetType;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 150, 150, 250, 120);
var tdf = shape.getThreeDFormat();
tdf.getBevelTop().setBevelType(BevelPresetType.CIRCLE);
tdf.getBevelTop().setWidth(10);
tdf.getCamera().setCameraType(CameraPresetType.PERSPECTIVE_ABOVE);
prs.save("camera.pptx", SaveFormat.PPTX);
}Light Rig and Material
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
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.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.RECTANGLE, 150, 150, 250, 120);
shape.addTextFrame("Metal Button");
var 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);
}MaterialPresetType values: MATTE, WARM_MATTE, PLASTIC, METAL, FLAT, SOFT_EDGE, CLEAR
Combining 2D and 3D Effects
You can apply both getEffectFormat() and getThreeDFormat() to the same shape:
import org.aspose.slides.foss.Presentation;
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.MaterialPresetType;
import org.aspose.slides.foss.Color;
import org.aspose.slides.foss.SaveFormat;
try (Presentation prs = new Presentation()) {
var shape = prs.getSlides().get(0).getShapes().addAutoShape(ShapeType.ROUND_CORNER_RECTANGLE, 150, 150, 300, 120);
shape.addTextFrame("Premium Card");
// Solid fill
shape.getFillFormat().setFillType(FillType.SOLID);
shape.getFillFormat().getSolidFillColor().setColor(Color.fromArgb(255, 30, 80, 180));
// 3D bevel
var tdf = shape.getThreeDFormat();
tdf.getBevelTop().setBevelType(BevelPresetType.CIRCLE);
tdf.getBevelTop().setWidth(8);
tdf.getCamera().setCameraType(CameraPresetType.PERSPECTIVE_ABOVE);
tdf.setMaterial(MaterialPresetType.PLASTIC);
// Drop shadow
var 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);
}