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