欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能

 更新時間:2022年08月01日 09:45:20   作者:Gia-  
由于大多數(shù)便攜式設(shè)備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對于用戶而言更加友好。本文將利用C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能,需要的可以參考一下

由于大多數(shù)便攜式設(shè)備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對于用戶而言更加友好。除此之外,將PowerPoint文檔轉(zhuǎn)換為圖像也可以防止對內(nèi)容做出修改。在本文中,我將展示如何使用 Spire.Presentation for .NET 在C#/VB.NET程序中,將PowerPoint(PPT 和 PPTX)轉(zhuǎn)換為 PNG 或 SVG。

安裝 Spire.Presentation for .NET

首先,我們需要將 Spire.Presentation for .NET 包中包含的 DLL 文件添加為 .NET 項(xiàng)目中的引用。可以從此鏈接下載 DLL 文件,也可以通過NuGet 安裝 DLL 文件。

PM> Install-Package Spire.Presentation

將PPT或PPTX轉(zhuǎn)換為PNG

C#

using Spire.Presentation;
using System;
using System.Drawing;
using System.Drawing.Imaging;
 
namespace ConvertPowerPointToPng
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化Presentation實(shí)例
            Presentation presentation = new Presentation();

            //加載一個PowerPoint文檔
            presentation.LoadFromFile("模板.pptx");

            //遍歷PowerPoint文檔中的幻燈片并保存為PNG圖片
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                Image image = presentation.Slides[i].SaveAsImage();
                String fileName = String.Format("圖片{0}.png", i);
                image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
    }
}

VB.NET

Imports Spire.Presentation
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
 
Namespace ConvertPowerPointToPng
    Class Program
        Shared  Sub Main(ByVal args() As String)
            '初始化Presentation實(shí)例
            Dim presentation As Presentation =  New Presentation() 
 
            '加載一個PowerPoint文檔
            presentation.LoadFromFile("模板.pptx")
 
            '遍歷PowerPoint文檔中的幻燈片并保存為PNG圖片
            Dim i As Integer
            For  i = 0 To  presentation.Slides.Count- 1  Step  i + 1
                Dim image As Image =  presentation.Slides(i).SaveAsImage() 
                Dim fileName As String =  String.Format("圖片{0}.png",i) 
                image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png)
            Next
        End Sub
    End Class
End Namespace

效果圖

將PPT或PPTX轉(zhuǎn)換為SVG

C#

using System.Collections.Generic;
using System.IO;
namespace PPTtoSVG
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化Presentation實(shí)例
            Presentation presentation = new Presentation();

            //加載一個PowerPoint文檔
            presentation.LoadFromFile("模板.pptx");

            //將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲在列隊中
            Queue<byte[]> svgBytes = presentation.SaveToSVG();

            //獲取列隊中字節(jié)數(shù)組生成SVG文件
            int len = svgBytes.Count;
            for (int i = 0; i < len; i++)
            {
                FileStream fs = new FileStream(string.Format("圖片-{0}.svg", i), FileMode.Create);
                byte[] bytes = svgBytes.Dequeue();
                fs.Write(bytes, 0, bytes.Length);
                presentation.Dispose();
            }
        }
    }
}

VB.NET

Imports System.Collections.Generic
Imports System.IO
Namespace PPTtoSVG
    Class Program
        Shared  Sub Main(ByVal args() As String)
            '初始化Presentation實(shí)例
            Dim presentation As Presentation =  New Presentation() 
 
            '加載一個PowerPoint文檔
            presentation.LoadFromFile("模板.pptx")
 
            '將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲在列隊中
            Dim svgBytes()> As Queue<byte =  presentation.SaveToSVG() 
 
            '獲取列隊中字節(jié)數(shù)組生成SVG文件
            Dim len As Integer =  svgBytes.Count 
            Dim i As Integer
            For  i = 0 To  len- 1  Step  i + 1
                Dim fs As FileStream =  New FileStream(String.Format("圖片-{0}.svg",i),FileMode.Create) 
                Dim bytes() As Byte =  svgBytes.Dequeue() 
                fs.Write(bytes, 0, bytes.Length)
                presentation.Dispose()
            Next
        End Sub
    End Class
End Namespace

效果圖

以上就是C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能的詳細(xì)內(nèi)容,更多關(guān)于C# PPT轉(zhuǎn)圖像的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論