翻譯|使用教程|編輯:李顯亮|2021-09-02 09:53:46.850|閱讀 585 次
概述:在本文中,將學習如何使用 C# 生成 PowerPoint PPTX 或 PPT 的縮略圖。這在您需要創建自己的 Web 或基于桌面的 PowerPoint 查看器等情況下可能很有用。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
縮略圖通常用于創建較大圖像的小尺寸版本。它們使查看或滾動圖像列表變得更加容易。MS PowerPoint 還為您提供演示文稿中幻燈片的縮略圖。使用幻燈片的縮略圖,可以輕松瀏覽演示文稿并導航到特定幻燈片。在本文中,將學習如何使用 C# 生成 PowerPoint PPTX 或 PPT 的縮略圖。這在需要創建自己的 Web 或基于桌面的 PowerPoint 查看器等情況下可能很有用。
為了生成 PPTX 或 PPT 演示文稿的縮略圖,我們將使用Aspose.Slides for .NET,它是一個強大的 API,可讓您創建和操作 PowerPoint 和 OpenOffice 文檔。此外,它還允許您將演示文稿轉換為其他文件格式。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
以下是使用 C# 生成 PPTX 演示文稿縮略圖的步驟。
以下代碼示例展示了如何使用 C# 生成 PPTX 演示文稿的縮略圖。
// Load PowerPoint presentation using (Presentation pres = new Presentation("presentation.pptx")) { foreach (ISlide sld in pres.Slides) { // Create a full scale image Bitmap bmp = sld.GetThumbnail(1f, 1f); // Save the image to disk in JPEG format bmp.Save(String.Format("slide_{0}.jpg", sld.SlideNumber), System.Drawing.Imaging.ImageFormat.Jpeg); } }
還可以根據需要自定義縮略圖的尺寸。這可以使用Presentation.SlideSize.Size.Width和Presentation.SlideSize.Size.Height屬性來實現。以下是執行此操作的步驟。
以下代碼示例展示了如何生成具有自定義尺寸的 PPTX 縮略圖。
// Load PowerPoint presentation using (Presentation pres = new Presentation("presentation.pptx")) { // User defined dimension int desiredX = 1200; int desiredY = 800; // Getting scaled value of X and Y float ScaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX; float ScaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY; foreach (ISlide sld in pres.Slides) { // Create a full scale image Bitmap bmp = sld.GetThumbnail(ScaleX, ScaleY); // Save the image to disk in JPEG format bmp.Save(String.Format("slide_{0}.jpg", sld.SlideNumber), System.Drawing.Imaging.ImageFormat.Jpeg); } }
如果你想試用Aspose的全部完整功能,可 聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn