Java 给PPT添加动画效果(预设动画/自定义动画)
PPT幻灯片中对形状可设置动画效果,常见的动画效果为内置的固定类型,即动画效果和路径是预先设定好的固定模板,但在设计动画效果时,用户也可以按照自己的喜好自定义动画动作路径。下面,通过Java后端程序代码来展示如何给PPT添加动画效果。包括预设动画以及自定动画效果的方法。
本次测试环境包括:
- 目标测试文档:Power Point 2013
- 编译环境:IntelliJ IDEA 2018
- JDK版本:1.8.0
- PPT库版本:spire.presentation.jar 4.3.2
注:在通过该PPT库来添加动画类型(AnimationEffectType)时,可添加约150种不同类型。
Java程序代码
1. 添加预设动画效果
a. 新建PPT文档,添加形状,设置动画效果
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.AnimationEffectType;
import java.awt.*;
import java.awt.geom.Rectangle2D; public class AddAnimationToShape {
public static void main(String[]args) throws Exception{
//创建PowerPoint文档
Presentation ppt = new Presentation();
//获取幻灯片
ISlide slide = ppt.getSlides().get(0); //添加一个形状到幻灯片
IAutoShape shape = slide.getShapes().appendShape(ShapeType.CUBE, new Rectangle2D.Double(50, 150, 150, 150));
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.orange);
shape.getShapeStyle().getLineColor().setColor(Color.white); //设置形状动画效果
slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.CHANGE_LINE_COLOR); //保存文档
ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013);
}
}
b.加载已有PPT文档,获取形状动画效果,进行动画效果设置,这里可做更为详细的动画设置,包括动画重复播放类型、次数、持续时间、延迟时间等.
import com.spire.presentation.*;
import com.spire.presentation.drawing.animation.AnimationEffect; public class RepeatAnimation {
public static void main(String[] args) throws Exception{
//加载测试文档
Presentation ppt = new Presentation();
ppt.loadFromFile("test.pptx");
//获取第一张幻灯片
ISlide slide = ppt.getSlides().get(0);
//获取幻灯片中第一个动画效果
AnimationEffect animation = slide.getTimeline().getMainSequence().get(0); //设置动画效果循环播放类型、次数、持续时间、延迟时间
animation.getTiming().setAnimationRepeatType(AnimationRepeatType.Number);
animation.getTiming().setRepeatCount(2);//设置重复次数
animation.getTiming().setDuration(2);//设置持续时间
animation.getTiming().setTriggerDelayTime(2);//设置延迟时间
//animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilEndOfSlide);//设置动画循环播放至幻灯片末
//animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilNextClick);//设置动画循环播放至下次点击 //保存结果文档
ppt.saveToFile("RepeatAnimation.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
2. 添加自定义动画效果
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 {
//创建一个空白PPT文档
Presentation ppt = new Presentation(); //获取第一张幻灯片(新建的幻灯片文档默认已包含一张幻灯片)
ISlide slide = ppt.getSlides().get(0); //添加形状到幻灯片
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); //添加动画效果,并设置动画效果类型为PATH_USER(自定义类型)
AnimationEffect effect = slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.PATH_USER); //获取自定动画的CommonBehavior集合
CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection(); //设置动画动作运动起点及路径模式
AnimationMotion motion = (AnimationMotion)commonBehaviorCollection.get(0);
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();
}
}
以上是本次Java给PPT添加动画效果的全部内容。如需转载,请注明出处!
Java 给PPT添加动画效果(预设动画/自定义动画)的更多相关文章
- Android 动画之View动画效果和Activity切换动画效果
View动画效果: 1.>>Tween动画通过对View的内容进行一系列的图形变换(平移.缩放.旋转.透明度变换)实现动画效果,补间动画需要使用<set>节点作为根节点,子节点 ...
- css动画效果之transition(动画过渡效果属性)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- AndroidUI 视图动画-混合动画效果 (AnimationSet)/动画效果监听
在前面介绍了几种动画效果:透明动画效果(AlphsAnimation).移动动画效果(TranslateAnimation).旋转动画效果(RotateAnimation).缩放动画效果(ScaleA ...
- CSS3动画效果——js调用css动画属性并回调处理详解
http://www.jb51.net/css/258407.html 这篇文章主要详细介绍了CSS3动画效果回调处理,需要的朋友可以参考下 我们在做js动画的时候,很多时候都需要做回调处理,如在一个 ...
- css3动画效果:3 3D动画
立方体旋转动画效果 css #container{ width: 400px; height: 400px; ; ; -webkit-perspective-origin:50% 225px; per ...
- css动画效果之transition(动画效果属性)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- css3动画效果:2 简易动画
1. transition动画:鼠标移上去 旋转放大 关键点-- :hover \ transform: scale(*) rotate(*deg) cards 2.关键帧动画: 位移动画 t ...
- Android动画效果之自定义ViewGroup添加布局动画
前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...
- Android动画效果之Tween Animation(补间动画)
前言: 最近公司项目下个版本迭代里面设计了很多动画效果,在以往的项目中开发中也会经常用到动画,所以在公司下个版本迭代开始之前,抽空总结一下Android动画.今天主要总结Tween Animation ...
随机推荐
- prototype chain & prototype & __proto__
prototype chain & prototype & proto prototype chain MDN https://developer.mozilla.org/en-US/ ...
- how to group date array by month in javascript
how to group date array by month in javascript https://stackoverflow.com/questions/14446511/most-eff ...
- Flutter: MobX和flutter_mobx状态管理器
MobX.dart网站上的 " 入门指南" mobxjs video 组织Stores 安装依赖 dependencies: mobx: flutter_mobx: dev_dep ...
- Flutter 真机调试
先把手机开启开发者模式,并打开USB调试功能(每种机型开启方法可能不一样) flutter devices 查看是否连接 flutter run
- Renice INC:不同颜色的酒帽所代表的意义
酒帽就是酒瓶上方的热缩胶帽/锡帽/蜡封,也就是开瓶前要割掉的那一层保护物,所有的法国酒在酒帽上,都会有一个圆形贴纸,除了有不同颜色外,上面还有一串号码,有可能很多人在喝酒时都不会对这个酒帽有更多的在意 ...
- BGV币与YFI币、YFII币存在着怎样的相关性?
大多数的玩家并没有长期的打算,而是更倾向于关注短期利好的币种.比如最近在圈内赚足眼球的YFI,之所以能够成为明星角色,并非它的技术和平台,而是因为它在短期就创造了86倍的暴涨.YFI币的暴涨在某种程度 ...
- transient的作用及序列化
1.transient 介绍 Java中的transient关键字,transient是短暂的意思.对于transient 修饰的成员变量,在类的实例对象的序列化处理过程中会被忽略. 因此,trans ...
- 11_MySQL如何让数据分页显示
-- 数据分页 SELECT empno,sal FROM t_emp LIMIT 5;
- C语言指针基本知识
对程序进行编译的时候,系统会把变量分配在内存单位中,根据不同的变量类型,分配不同的字节大小.比如int整型变量分配4个字节,char字符型变量分配1个字节等等.被分配在内存的变量,可以通过地址去找到, ...
- 1102 Invert a Binary Tree——PAT甲级真题
1102 Invert a Binary Tree The following is from Max Howell @twitter: Google: 90% of our engineers us ...