Työskenteleminen 3D-efektien ja visuaalisten efektien kanssa — Aspose.Slides FOSS for Java
Aspose.Slides FOSS for Java provides two separate effect systems accessible on every shape:
EffectFormat(shape.getEffectFormat()): 2D visuaaliset tehosteet: varjo, hehku, pehmeä reuna, sumennus, heijastusThreeDFormat(shape.getThreeDFormat()): 3D-ulkonäkö: viiste, kameraprojektio, valaisinjärjestelmä, materiaali, ulostuksen syvyys
Molemmat säilyvät tallennus- ja latausjaksojen aikana.
Visuaaliset efektit (EffectFormat)
Ulkoinen varjostus
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);
}Yleinen direction arvot: 0 = oikea, 45 = alaoikea, 90 = alas, 270 = ylös, 315 = ylävasen.
Hehkuva efekti
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);
}Pehmeä reuna (häivytetty reunus)
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);
}Sumennus
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);
}Efektien tarkistaminen ja poistaminen
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)
Viistoeffekt
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-arvot: CIRCLE, RELAXED_INSET, COOL_SLANT, DIVOT, RIBLET, HARD_EDGE, SLOPE, CONVEX
Kameran esiasetus
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);
}Valon rig ja materiaali
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-arvot: MATTE, WARM_MATTE, PLASTIC, METAL, FLAT, SOFT_EDGE, CLEAR
2D- ja 3D-efektien yhdistäminen
Voit käyttää molempia getEffectFormat() ja getThreeDFormat() samaan muotoon:
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);
}