翻譯|使用教程|編輯:李顯亮|2021-09-22 09:40:56.430|閱讀 430 次
概述:在本文中,將學(xué)習(xí)如何以編程方式處理演示文稿中的視頻。特別是,本文將介紹如何使用 C# 在 PowerPoint 演示文稿中嵌入或提取視頻。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PowerPoint 演示文稿中使用視頻幀來(lái)演示某些內(nèi)容或吸引觀眾。通常,視頻用于節(jié)省時(shí)間并使演示更有效。在本文中,將學(xué)習(xí)如何以編程方式處理演示文稿中的視頻。特別是,本文將介紹如何使用 C# 在 PowerPoint 演示文稿中嵌入或提取視頻。
為了在 PowerPoint 演示文稿中嵌入或提取視頻,我們將使用Aspose.Slides for .NET,API 旨在創(chuàng)建和操作 PowerPoint 和 OpenOffice 文檔。
>>你可以點(diǎn)擊這里下載Aspose.Slides 最新版測(cè)試體驗(yàn)。
以下是使用 C# 在 PowerPoint 演示文稿中嵌入視頻的步驟。
以下代碼示例展示了如何使用 C# 在 PowerPoint 演示文稿中嵌入視頻。
// Instantiate Presentation class that represents the PPTX using (Presentation pres = new Presentation()) { // Get the first slide ISlide sld = pres.Slides[0]; // Add video to presentation IVideo vid = pres.Videos.AddVideo(new FileStream("Wildlife.mp4", FileMode.Open)); // Add video frame IVideoFrame vf = sld.Shapes.AddVideoFrame(50, 150, 300, 350, vid); // Assign video to video frame vf.EmbeddedVideo = vid; // Set play mode and volume of the video vf.PlayMode = VideoPlayModePreset.Auto; vf.Volume = AudioVolumeMode.Loud; // Write the PPTX file to disk pres.Save("VideoFrame_out.pptx", SaveFormat.Pptx); }
還可以在 PowerPoint 演示文稿中嵌入來(lái)自 Web 源的視頻。以下是實(shí)現(xiàn)此目的的步驟。
以下代碼示例展示了如何將來(lái)自 Web 源的視頻嵌入到演示文稿中。
using (Presentation pres = new Presentation()) { // Video ID string videoId = "Tj75Arhq5ho"; // Add video frame IVideoFrame videoFrame = pres.Slides[0].Shapes.AddVideoFrame(10, 10, 427, 240, "http://www.youtube.com/embed/" + videoId); videoFrame.PlayMode = VideoPlayModePreset.Auto; // Load thumbnail using (WebClient client = new WebClient()) { string thumbnailUri = "http://img.youtube.com/vi/" + videoId + "/hqdefault.jpg"; videoFrame.PictureFormat.Picture.Image = pres.Images.AddImage(client.DownloadData(thumbnailUri)); } // Save presentation pres.Save("AddVideoFrameFromWebSource_out.pptx", SaveFormat.Pptx); }
Aspose.Slides for .NET 還允許您從演示文稿中提取視頻。以下是實(shí)現(xiàn)此目的的簡(jiǎn)單步驟。
以下代碼示例展示了如何使用 C# 從 PowerPoint 演示文稿中提取視頻。
// Load a presentation file Presentation presentation = new Presentation("Video.pptx"); // Loop through slides in the presentation foreach (ISlide slide in presentation.Slides) { // Loop through shapes foreach (IShape shape in presentation.Slides[0].Shapes) { if (shape is VideoFrame) { // Extract and save video IVideoFrame vf = shape as IVideoFrame; String type = vf.EmbeddedVideo.ContentType; int ss = type.LastIndexOf('/'); type = type.Remove(0, type.LastIndexOf('/') + 1); Byte[] buffer = vf.EmbeddedVideo.BinaryData; using (FileStream stream = new FileStream("NewVideo_out." + type, FileMode.Create, FileAccess.Write, FileShare.Read)) { stream.Write(buffer, 0, buffer.Length); } } } }
如果你想試用Aspose的全部完整功能,可聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn