Java 給PPT添加動(dòng)畫(huà)效果的示例
PPT幻燈片中對(duì)形狀可設(shè)置動(dòng)畫(huà)效果,常見(jiàn)的動(dòng)畫(huà)效果為內(nèi)置的固定類(lèi)型,即動(dòng)畫(huà)效果和路徑是預(yù)先設(shè)定好的固定模板,但在設(shè)計(jì)動(dòng)畫(huà)效果時(shí),用戶也可以按照自己的喜好自定義動(dòng)畫(huà)動(dòng)作路徑。下面,通過(guò)Java后端程序代碼來(lái)展示如何給PPT添加動(dòng)畫(huà)效果。包括預(yù)設(shè)動(dòng)畫(huà)以及自定動(dòng)畫(huà)效果的方法。
本次測(cè)試環(huán)境包括:
- 目標(biāo)測(cè)試文檔:Power Point 2013
- 編譯環(huán)境:IntelliJ IDEA 2018
- JDK版本:1.8.0
- PPT庫(kù)版本:spire.presentation.jar 4.3.2
注:在通過(guò)該P(yáng)PT庫(kù)來(lái)添加動(dòng)畫(huà)類(lèi)型(AnimationEffectType)時(shí),可添加約150種不同類(lèi)型。
Java程序代碼
1. 添加預(yù)設(shè)動(dòng)畫(huà)效果
a. 新建PPT文檔,添加形狀,設(shè)置動(dòng)畫(huà)效果
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{ //創(chuàng)建PowerPoint文檔 Presentation ppt = new Presentation(); //獲取幻燈片 ISlide slide = ppt.getSlides().get(0); //添加一個(gè)形狀到幻燈片 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); //設(shè)置形狀動(dòng)畫(huà)效果 slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.CHANGE_LINE_COLOR); //保存文檔 ppt.saveToFile("AddAnimationToShape.pptx", FileFormat.PPTX_2013); } }
b.加載已有PPT文檔,獲取形狀動(dòng)畫(huà)效果,進(jìn)行動(dòng)畫(huà)效果設(shè)置,這里可做更為詳細(xì)的動(dòng)畫(huà)設(shè)置,包括動(dòng)畫(huà)重復(fù)播放類(lèi)型、次數(shù)、持續(xù)時(shí)間、延遲時(shí)間等.
import com.spire.presentation.*; import com.spire.presentation.drawing.animation.AnimationEffect; public class RepeatAnimation { public static void main(String[] args) throws Exception{ //加載測(cè)試文檔 Presentation ppt = new Presentation(); ppt.loadFromFile("test.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.getSlides().get(0); //獲取幻燈片中第一個(gè)動(dòng)畫(huà)效果 AnimationEffect animation = slide.getTimeline().getMainSequence().get(0); //設(shè)置動(dòng)畫(huà)效果循環(huán)播放類(lèi)型、次數(shù)、持續(xù)時(shí)間、延遲時(shí)間 animation.getTiming().setAnimationRepeatType(AnimationRepeatType.Number); animation.getTiming().setRepeatCount(2);//設(shè)置重復(fù)次數(shù) animation.getTiming().setDuration(2);//設(shè)置持續(xù)時(shí)間 animation.getTiming().setTriggerDelayTime(2);//設(shè)置延遲時(shí)間 //animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilEndOfSlide);//設(shè)置動(dòng)畫(huà)循環(huán)播放至幻燈片末 //animation.getTiming().setAnimationRepeatType(AnimationRepeatType.UtilNextClick);//設(shè)置動(dòng)畫(huà)循環(huán)播放至下次點(diǎn)擊 //保存結(jié)果文檔 ppt.saveToFile("RepeatAnimation.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }
2. 添加自定義動(dòng)畫(huà)效果
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 { //創(chuàng)建一個(gè)空白PPT文檔 Presentation ppt = new Presentation(); //獲取第一張幻燈片(新建的幻燈片文檔默認(rèn)已包含一張幻燈片) 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); //添加動(dòng)畫(huà)效果,并設(shè)置動(dòng)畫(huà)效果類(lèi)型為PATH_USER(自定義類(lèi)型) AnimationEffect effect = slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.PATH_USER); //獲取自定動(dòng)畫(huà)的CommonBehavior集合 CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection(); //設(shè)置動(dòng)畫(huà)動(dòng)作運(yùn)動(dòng)起點(diǎn)及路徑模式 AnimationMotion motion = (AnimationMotion)commonBehaviorCollection.get(0); motion.setOrigin(AnimationMotionOrigin.LAYOUT); motion.setPathEditMode(AnimationMotionPathEditMode.RELATIVE); //設(shè)置動(dòng)作路徑 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); //設(shè)置動(dòng)作路徑到動(dòng)畫(huà) motion.setPath(motionPath); //保存文檔 ppt.saveToFile("result.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }
以上就是Java 給PPT添加動(dòng)畫(huà)效果的示例的詳細(xì)內(nèi)容,更多關(guān)于Java 給PPT添加動(dòng)畫(huà)效果的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Java如何為 PPT 中的圖形添加陰影效果
- Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例
- Java 在PPT中添加文本和圖片超鏈接的實(shí)現(xiàn)方法
- Java 在PPT中添加混合圖表過(guò)程詳解
- java實(shí)現(xiàn)在線預(yù)覽--poi實(shí)現(xiàn)word、excel、ppt轉(zhuǎn)html的方法
- Java 添加文本框到PPT幻燈片過(guò)程解析
- Java如何在PPT中繪制圖形
- 淺談Java設(shè)置PPT幻燈片背景——純色、漸變、圖片背景
- Java使用jacob將微軟office中word、excel、ppt轉(zhuǎn)成pdf
相關(guān)文章
SpringBoot后臺(tái)實(shí)現(xiàn)文件上傳下載
這篇文章主要為大家詳細(xì)介紹了SpringBoot后臺(tái)實(shí)現(xiàn)文件上傳下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02Spring配置多數(shù)據(jù)源導(dǎo)致事物無(wú)法回滾問(wèn)題
這篇文章主要介紹了Spring配置多數(shù)據(jù)源導(dǎo)致事物無(wú)法回滾問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01SpringSecurity+Redis+Jwt實(shí)現(xiàn)用戶認(rèn)證授權(quán)
SpringSecurity是一個(gè)強(qiáng)大且靈活的身份驗(yàn)證和訪問(wèn)控制框架,本文主要介紹了SpringSecurity+Redis+Jwt實(shí)現(xiàn)用戶認(rèn)證授權(quán),具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07mybatis-plus通用枚舉@JsonValue接收參數(shù)報(bào)錯(cuò)No enum constant
最近在使用mybatis-plus時(shí)用到了通用枚舉,遇到了問(wèn)題,本文主要介紹了mybatis-plus通用枚舉@JsonValue接收參數(shù)報(bào)錯(cuò)No enum constant,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09Java list利用遍歷進(jìn)行刪除操作3種方法解析
這篇文章主要介紹了Java list利用遍歷進(jìn)行刪除操作3種方法解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01解析Linux系統(tǒng)中JVM內(nèi)存2GB上限的詳解
本篇文章是對(duì)Linux系統(tǒng)中JVM內(nèi)存2GB上限進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05spring @Scheduled注解的使用誤區(qū)及解決
這篇文章主要介紹了spring @Scheduled注解的使用誤區(qū)及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11