翻譯|使用教程|編輯:李顯亮|2020-02-11 11:39:05.320|閱讀 1455 次
概述:當我們需要將PowerPoint(PPT或PPTX)幻燈片轉換為JPG圖像時,可能會有多種情況。為了自動將PowerPoint轉換為JPG,在本文中將展示如何在C#.NET中以編程方式將PPT/PPTX幻燈片轉換為JPG圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
當我們需要將PowerPoint(PPT或PPTX)幻燈片轉換為JPG圖像時,可能會有多種情況。例如,可能需要在應用程序中以只讀模式幻燈片顯示PPT / PPTX演示文稿,或者希望為PowerPoint演示文稿的每張幻燈片等生成縮略圖。為了自動將PowerPoint轉換為JPG,在本文中將展示如何在C#.NET中以編程方式將PPT/PPTX幻燈片轉換為JPG圖像。
為了將PPT/PPTX轉換為JPG圖像,文本將使用Aspose.Slides for .NET,這是用于PowerPoint自動化的完整.NET軟件包。該API可將PowerPoint演示文稿高質量轉換為包括JPG在內的各種文件格式。很高興的是,Aspose.Slides已經迎來2020第一次更新,增強了多項功能,如果你還沒有升級Aspose.Slides最新版測試,可以點擊這里下載。
以下是使用Aspose.Slides for .NET將PPT轉換為JPG的步驟:
下面的代碼示例演示如何在C#中將PPT轉換為JPG圖像。
using (Presentation pres = new Presentation("PowerPoint-Presentation.ppt")) { 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); } }
PPT演示文件
轉換后的JPG圖像
當然,可以根據需要自定義JPG圖像的尺寸。下面的代碼示例演示如何在C#中將PPTX轉換為JPG時定義ScaleX和ScaleY值。
using (Presentation pres = new Presentation("PowerPoint-Presentation.pptx")) { // Define dimensions int desiredX = 1200; int desiredY = 800; // Get scaled values 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); } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn