文章插圖

文章插圖
PowerPoint 演示文稿是我們常用的辦公軟件之一 。為了能夠更加全面細致地展示要說明的內容,視頻不失為一種很好的展示方式 。本文將使用Java代碼來演示如何插入視頻到PowerPoint幻燈片,同時也將介紹提取視頻以及設置視頻播放模式的方法 。
使用工具:Free Spire.Presentation for Java測試環境:JDK 1.8.0、Intellij IDEA 2019Jar包導入:
方式一:在E-iceblue中文官網上下載產品包,解壓后在lib文件夾下找到Spire.Presentation.jar,然后手動將其導入IDEA 。
方式二:在IDEA中創建Maven項目,然后在pom.xml下鍵入以下代碼,最后點擊“Import Changes”即可 。
<repositories><repository><id>com.e-iceblue</id><url>http://repo.e-iceblue.cn/repository/maven-public/</url></repository></repositories><dependencies><dependency><groupId>e-iceblue</groupId><artifactId>spire.presentation.free</artifactId><version>3.9.0</version></dependency></dependencies>代碼示例示例一 插入視頻到PowerPoint幻燈片
import com.spire.presentation.*;import javax.imageio.ImageIO;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import java.io.File;public class InsertVideo {public static void main(String[] args) throws Exception {//加載PowerPoint示例文檔Presentation presentation = new Presentation();presentation.loadFromFile("C:\Users\Test1\Desktop\Sample.pptx");//獲取第一張幻燈片ISlide slide = presentation.getSlides().get(0);//插入視頻到第一張幻燈片并設置封面圖片Rectangle2D.Double videoRect = new Rectangle2D.Double(150, 120, 400, 225);IVideo video = presentation.getSlides().get(0).getShapes().appendVideoMedia((new java.io.File("C:\Users\Test1\Desktop\video.mp4")).getAbsolutePath(), videoRect);BufferedImage coverImage = ImageIO.read( new File("C:\Users\Test1\Desktop\image.png"));video.getPictureFill().getPicture().setEmbedImage(presentation.getImages().append(coverImage));//保存結果文檔presentation.saveToFile("output/InsertVideo.pptx", FileFormat.PPTX_2010);presentation.dispose();}}效果圖:import com.spire.presentation.IShape;import com.spire.presentation.ISlide;import com.spire.presentation.IVideo;import com.spire.presentation.Presentation;public class ExtractVideo {public static void main(String[] args) throws Exception {//實例化一個ppt對象并加載示例文檔Presentation ppt = new Presentation();ppt.loadFromFile("C:\Users\Test1\Desktop\InsertVideo.pptx");//獲取第一張幻燈片ISlide slide = ppt.getSlides().get(0);IVideo video = null;for(int i = 0; i< slide.getShapes().getCount(); i++){IShape shape = slide.getShapes().get(i);if ((shape instanceof IVideo)) {//保存視頻video = (IVideo) shape;video.getEmbeddedVideoData().saveToFile("output/ExtractVideo"+i+".mp4");}}}}示例三 設置視頻播放模式import com.spire.presentation.FileFormat;import com.spire.presentation.IShape;import com.spire.presentation.ISlide;import com.spire.presentation.IVideo;import com.spire.presentation.Presentation;import com.spire.presentation.VideoPlayMode;public class PlayType {public static void main(String[] args) throws Exception {//實例化一個presentation對象并加載示例文檔Presentation presentation = new Presentation();presentation.loadFromFile("C:\Users\Test1\Desktop\InsertVideo.pptx");//獲取第一張幻燈片ISlide slide = presentation.getSlides().get(0);IVideo video = null;for(int i = 0; i< slide.getShapes().getCount(); i++){IShape shape = slide.getShapes().get(i);if ((shape instanceof IVideo)) {video = (IVideo) shape;//設置視頻的播放模式為自動播放//video.setPlayMode(VideoPlayMode.AUTO);//設置視頻的播放模式為單擊時播放video.setPlayMode(VideoPlayMode.ON_CLICK);}}//保存PPT文檔presentation.saveToFile("output/單擊播放.pptx", FileFormat.PPTX_2010);}}【ppt超鏈接視頻 如何在ppt鏈接視頻】設置效果:- 白芝麻油 黑芝麻油和白芝麻油的區別
- 超適合情侶打卡的5個地方 表白適合去哪些地方
- 超強邏輯思維讓人羨慕 邏輯思維強智慧的女人
- ppt用什么軟件做好看 ppt用什么軟件做好用
- 鄧超紋身位置 鄧超的紋身是什么意思
- 高情商男人8個撩妹,不得不服的高超撩妹
- 和女生聊天問答套路短句一問一答,這樣的套路女生超喜歡
- 愛發脾氣的毛爾冬 愛發脾氣的毛爾冬PPT
- 超高清電視排行榜 電視分辨率排行榜
- 如何開一家花店思維導圖 如何開一家花店PPT
