Animation effects can be set for shapes in PPT slides. Common animation effects are built-in fixed types, that is, animation effects and paths are preset fixed templates, but when designing animation effects, users can also customize them according to their own preferences. Define the animation motion path. Below, the Java back-end program code is used to show how to implement a custom action path.
The test environment includes:
Target test document: Power Point 2013
Compilation environment: IntelliJ IDEA 2018
JDK version: 1.8.0
PPT library: spire.presentation.jar 4.3.2
Note: When adding animation type (AnimationEffectType) through this PPT library, about 150 different types can be added. This article takes the custom type setting animation path as an example to introduce.
Java program code
import com.spire.presentation.*; import com.spire.presentation.collections.CommonBehaviorCollection; import com.spire.presentation.drawing.FillFormatType; import com.spire.presentation.drawing.animation.*; import java.awt.* ; import java.awt.geom.Point2D; public class CustomAnimationPath { public static void main(String[] args) throws Exception { //Create a blank PPT document Presentation ppt = new Presentation(); //Get the first slide (The newly created slide document already contains one slide by default) ISlide slide = ppt.getSlides().get(0); //Add a shape to the slide IAutoShape shape = slide.getShapes().appendShape(ShapeType.FIVE_POINTED_STAR, new Rectangle(180, 100, 170, 170)); shape.getFill().setFillType(FillFormatType.GRADIENT); animation motion AnimationMotion motion = (AnimationMotion) commonBehaviorCollection.get(0); shape.getFill().getGradient().getGradientStops().append(0, KnownColors.LIGHT_PINK); shape.getFill().getGradient().getGradientStops().append(1, KnownColors.PURPLE); shape.getShapeStyle( ).getLineColor().setColor(Color.white); //Add animation effect and set the animation effect type to PATH_USER (custom type) AnimationEffect effect = slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType. PATH_USER); //Get the CommonBehavior collection of custom animation CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection(); //Set the starting point and path mode of the animation motion motion.setOrigin(AnimationMotionOrigin.LAYOUT); motion.setPathEditMode(AnimationMotionPathEditMode.RELATIVE); //设置动作路径 MotionPath motionPath = new MotionPath(); motionPath.addPathPoints(MotionCommandPathType.MOVE_TO,new Point2D.Float[]{new Point2D.Float(0,0)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(0.1f,0.1f)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(-0.1f,0.2f)},MotionPathPointsType.CURVE_AUTO,true); motionPath.addPathPoints(MotionCommandPathType.END,new Point2D.Float[]{},MotionPathPointsType.CURVE_AUTO,true); //设置动作路径到动画 motion.setPath(motionPath); //保存文档 ppt.saveToFile("result.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }