Working with 3D Effects and Visual Effects — Aspose.Slides FOSS for Java

This guide shows how to apply visual effects and 3D formatting to shapes in PowerPoint presentations using Aspose.Slides FOSS for Java. Every shape exposes two formatting objects:

  • EffectFormat (shape.getEffectFormat()): 2D visual effects — shadow, glow, soft edge, blur, reflection
  • ThreeDFormat (shape.getThreeDFormat()): 3D appearance — bevel, camera projection, light rig, material, extrusion depth

Both formatting objects persist through save/reload cycles.


Visual Effects (EffectFormat)

Outer Drop Shadow

Call ef.enableOuterShadowEffect() to activate the outer shadow, then set blurRadius, direction, distance, and shadowColor:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.drawing.Color;
import org.aspose.slides.foss.export.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

Call ef.enableGlowEffect() to add a colored glow around the shape, then set radius and the glow color:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.drawing.Color;
import org.aspose.slides.foss.export.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)

Call ef.enableSoftEdgeEffect() to add a feathered border around the shape, then set radius to control the feather distance in points:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.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

Call shape.getEffectFormat().setBlurEffect() with a blur radius and a grow flag to apply a blur effect to the shape:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.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

Check ef.isNoEffects() to detect whether any effect is active, then call disableOuterShadowEffect() or disableGlowEffect() to remove specific 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

Set tdf.getBevelTop().setBevelType() to a BevelPresetType value and configure width and height to apply a bevel to the top face of the shape:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.BevelPresetType;
import org.aspose.slides.foss.export.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

Set tdf.getCamera().setCameraType() to a CameraPresetType value to change the projection angle applied to the 3D shape:

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.export.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

Set tdf.getLightRig().setLightType() and tdf.getLightRig().setDirection() to control how light falls on the shape, then set tdf.setMaterial() to one of the MaterialPresetType values:

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.export.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.drawing.Color;
import org.aspose.slides.foss.export.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);
}

See Also

 English