さまざまな目的で、PowerPoint を画像に変換する必要があります。 たとえば、他のユーザーが PowerPoint ドキュメントの内容を編集できないようにします、PowerPoint ドキュメントのサムネイルを生成します、ソーシャル メディアで PowerPoint ドキュメントを共有します。この記事では、Spire.Presentation for .NET を使用して、C# および VB.NET で PowerPoint を画像に変換する方法を示します。 PowerPoint を JPG または PNG に変換する PowerPoint を TIFF に変換する PowerPoint を EMF に変換する PowerPoint を SVG に変換する Spire.Presentation for.NET をインストールします まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGetを介してインストールできます。 PM> Install-Package Spire.Presentation PowerPoint を JPG または PNG に変換する Spire.Presentation for .NET が提供する ISlide.SaveAsImage() メソッドでは、スライドを PNG または JPG に変換することがサポートします。以下に詳細な変換手順を示します。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。 PowerPoint ドキュメント内のすべてのスライドをループします。 ISlide.SaveAsImage() メソッドを使用して、スライドを System.Drawing.Image オブジェクトとして保存します。 Image.Save() メソッドを使用して、画像オブジェクトを PNG または JPG ファイルとして保存します。 C# VB.NET using Spire.Presentation; using System.Drawing; namespace ConvertPowerPointToJpgOrPngImage { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Sample.pptx"); int i = 0; //すべてのスライドをループする foreach(ISlide slide in presentation.Slides) { //画像オブジェクトをPNGとして保存する Image image = slide.SaveAsImage(); string fileName = string.Format("ToImage-img-{0}.png", i); image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); i++; } } } } Imports Spire.Presentation Namespace ConvertPowerPointToJpgOrPngImage Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Sample.pptx") Dim i = 0 'すべてのスライドをループする For Each slide As ISlide In presentation.Slides '画像をPNGとして保存する Dim image As Image = slide.SaveAsImage() Dim fileName = String.Format("ToImage-img-{0}.png", i) image.Save(fileName, Drawing.Imaging.ImageFormat.Png) i += 1 Next End Sub End Class End Namespace PowerPoint を TIFF に変換する Spire.Presentation for .NET が提供する Presentation.SaveToFile(string, FileFormat) メソッドでは、PowerPoint を TIFF に変換することがサポートします。以下に詳細な変換手順を示します。 Presentationクラスのインスタンスを初期化します。 Presentation.LoadFromFile()メソッドを使用してPowerPointドキュメントをロードします。 Presentation.SaveToFile(string, FileFormat)メソッドを使用してPowerPointドキュメントをTIFFイメージに変換します。 C# VB.NET using Spire.Presentation; namespace ConvertPowerPointToTiffImage { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Sample.pptx"); //画像をTIFFとして保存する presentation.SaveToFile("toTIFF.tiff", FileFormat.Tiff); } } } Imports Spire.Presentation Namespace ConvertPowerPointToTiffImage Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Sample.pptx") '画像をTIFFとして保存する presentation.SaveToFile("toTIFF.tiff", FileFormat.Tiff) End Sub End Class End Namespace PowerPoint を EMF に変換する Spire.Presentation for .NET が提供する ISlide.SaveAsEMF() メソッドでは、スライドを EMF に変換することがサポートします。以下に詳細な変換手順を示します。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。 PowerPoint ドキュメント内のすべてのスライドをループします。 ISlide.SaveAsEMF() メソッドを使用して、スライドを EMF として保存します。 C# VB.NET using Spire.Presentation; namespace ConvertPowerPointToEmfImage { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Sample.pptx"); int i = 0; //すべてのスライドをループする foreach (ISlide slide in presentation.Slides) { string fileName = string.Format("ToEmf-{0}.emf", i); //各スライドをEMFとして保存する slide.SaveAsEMF(fileName); //各スライドを指定した幅と高さのEMFとして保存する //slide.SaveAsEMF(fileName, 1075, 710); i++; } } } } Imports Spire.Presentation Namespace ConvertPowerPointToEmfImage Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Sample.pptx") Dim i = 0 'すべてのスライドをループする For Each slide As ISlide In presentation.Slides Dim fileName = String.Format("ToEmf-{0}.emf", i) '各スライドをEMFとして保存する slide.SaveAsEMF(fileName) '各スライドを指定した幅と高さのEMFとして保存する 'slide.SaveAsEMF(fileName, 1075, 710); i += 1 Next End Sub End Class End Namespace PowerPoint を SVG に変換する Spire.Presentation for .NET が提供する Presentation.SaveToSVG() メソッドは、PowerPoint を SVG に変換することができます。以下に詳細な変換手順を示します。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。 Presentation.SaveToSVG() メソッドを使用して PowerPoint を SVG に変換し、結果をバイト配列キューに保存します。 キュー内のバイト配列をループします。 Queue.Dequeue() メソッドを使用して、キューの先頭にあるバイト配列を削除して返します。 FileStream クラスのインスタンスを初期化する。FileStream.Write() メソッドを使用してバイト配列を SVG ファイルに保存します。 C# VB.NET using Spire.Presentation; using System.Collections.Generic; using System.IO; namespace ConvertPowerPointToSvgImage { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Sample.pptx"); //PowerPointをSVGに変換し、結果をバイト配列キューに保存する Queue svgBytes = presentation.SaveToSVG(); int count = svgBytes.Count; //キュー内のバイト配列をループする for (int i = 0; i < count; i++) { //キューの先頭にあるバイト配列を削除して返する byte[] bt = svgBytes.Dequeue(); //出力ファイル名を指定する string fileName = string.Format("ToSVG-{0}.svg", i); //FileStreamインスタンスを作成する FileStream fs = new FileStream(fileName, FileMode.Create); //SVGファイルへのバイト配列を保存する fs.Write(bt, 0, bt.Length); } } } } Imports Spire.Presentation Imports System.Collections.Generic Imports System.IO Namespace ConvertPowerPointToSvgImage Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Sample.pptx") 'PowerPointをSVGに変換し、結果をバイト配列キューに保存する Dim svgBytes As Queue(Of Byte()) = presentation.SaveToSVG() Dim count = svgBytes.Count 'キュー内のバイト配列をループする For i = 0 To count - 1 'キューの先頭にあるバイト配列を削除して返する Dim bt As Byte() = svgBytes.Dequeue() '出力ファイル名を指定する Dim fileName = String.Format("ToSVG-{0}.svg", i) 'FileStreamインスタンスを作成する Dim fs As FileStream = New FileStream(fileName, FileMode.Create) 'SVGファイルへのバイト配列を保存する fs.Write(bt, 0, bt.Length) Next End Sub End Class End Namespace 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。