Les effets d'animation peuvent être définis pour les formes des diapositives PPT. Les effets d'animation courants sont des types fixes intégrés, c'est-à-dire que les effets d'animation et les chemins sont des modèles fixes prédéfinis, mais lors de la conception d'effets d'animation, les utilisateurs peuvent également les personnaliser selon leurs propres préférences. Définissez la trajectoire du mouvement de l'animation. Ci-dessous, le code du programme Java back-end est utilisé pour montrer comment implémenter un chemin d'action personnalisé.
L'environnement de test comprend:
Document de test cible: Power Point 2013
Environnement de compilation: IntelliJ IDEA 2018
Version JDK: 1.8.0
Bibliothèque PPT: spire.presentation.jar 4.3.2
Remarque: Lors de l'ajout d'un type d'animation (AnimationEffectType) via cette bibliothèque PPT, environ 150 types différents peuvent être ajoutés. Cet article prend le chemin de l'animation de définition de type personnalisé comme exemple à présenter.
Code de programme Java
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 { // Créer un document PPT vierge Presentation ppt = new Presentation (); // Obtenir la première diapositive (Le le nouveau document de diapositive contient une diapositive par défaut) ISlide slide = ppt.getSlides (). get (0); // Ajoute une forme à la diapositive IAutoShape shape = slide.getShapes (). appendShape (ShapeType.FIVE_POINTED_STAR, new Rectangle ( 180, 100, 170, 170)); shape.getFill (). setFillType (FillFormatType.GRADIENT); shape.getFill (). getGradient (). getGradientStops (). append (0, KnownColors.LIGHT_PINK); shape.getFill (). getGradient (). getGradientStops (). append (1, KnownColors.PURPLE); shape.getShapeStyle ( ) .getLineColor (). setColor (Color.white); // Ajoute un effet d'animation et définit le type d'effet d'animation sur PATH_USER (type personnalisé) AnimationEffect effect = slide.getTimeline (). getMainSequence (). addEffect (shape, AnimationEffectType. PATH_USER ); // Récupère la collection CommonBehavior d'animation personnalisée CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection (); // Définit le point de départ et le mode de chemin de l'animation motion.setPathEditModeLATIVE (AnimationModeLATIVE) ; mouvement d'animation AnimationMotion motion = ( AnimationMotion) commonBehaviorCollection.get (0); motion.setOrigin (AnimationMotionOrigin.LAYOUT); // 设置 动作 路径 MotionPath motionPath = new MotionPath (); motionPath.addPathPoints (MotionCommandPathType.MOVE_TO, nouveau Point2D.Float [] {nouveau Point2D.Float (0,0)}, MotionPathPointsType.CURVE_AUTO, true); motionPath.addPathPoints (MotionCommandPathType.LINE_TO, nouveau Point2D.Float [] {nouveau Point2D.Float (0.1f, 0.1f)}, MotionPathPointsType.CURVE_AUTO, true); motionPath.addPathPoints (MotionCommandPathType.LINE_TO, nouveau Point2D.Float [] {nouveau Point2D.Float (-0.1f, 0.2f)}, MotionPathPointsType.CURVE_AUTO, true); motionPath.addPathPoints (MotionCommandPathType.END, nouveau Point2D.Float [] {}, MotionPathPointsType.CURVE_AUTO, true); // 设置 动作 路径 到 动画 motion.setPath (motionPath); // 保存 文档 ppt.saveToFile ("result.pptx", FileFormat.PPTX_2013); ppt.dispose (); } }