画像は PowerPoint で最も一般的な要素の 1 つです。 場合によっては、特定のスライドまたはプレゼンテーション全体から画像を抽出したい場合があります。 たとえば、それらの画像を別のプレゼンテーションで再利用したいとします。この記事では、Spire.Presentation for .NET を使用して C# で PowerPoint プレゼンテーションから画像を抽出する方法を示します。 C# で PowerPoint から画像を抽出する C# で PowerPoint のスライドから画像を抽出する Spire.Presentation for .NET をインストールします まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。 PM> Install-Package Spire.Presentation C# で PowerPoint から画像を抽出する PowerPoint 全体から画像を抽出するには、Presentation.Images プロパティを使用してプレゼンテーション内のすべての画像のコレクションを取得します。そして、コレクションを反復処理して ImageCollection[int].Image.Save() メソッドを使用して、各画像を画像ファイルに保存します。詳細な手順は次のとおりです。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint プレゼンテーションをロードします。 Presentation.Images プロパティでプレゼンテーション内のすべての画像のコレクションを 取得します。 コレクションを反復処理し、ImageCollection[int].Image.Save() メソッドを使用して、コレクション内の画像を画像ファイルに保存します。 C# using Spire.Presentation; using Spire.Presentation.Collections; using System.Drawing; namespace ExtractImagesFromPresentation { internal class Program { static void Main(string[] args) { //Presentation クラスのインスタンスを初期化する Presentation ppt = new Presentation(); //PowerPoint プレゼンテーションをロードする ppt.LoadFromFile(@"C:UsersAdministratorDesktopSample.pptx"); //プレゼンテーションの画像コレクションを取得する ImageCollection imageCollection = ppt.Images; //コレクション内の画像を反復処理する for (int i = 0; i < imageCollection.Count; i++) { //画像を抽出する imageCollection[i].Image.Save(string.Format(@"C:UsersAdministratorDesktopImagesImage{0}.png", i)); } ppt.Dispose(); } } } C# で PowerPoint のスライドから画像を抽出する 特定のスライドから画像を抽出するには、スライドのすべての図形を反復処理し、SlidePicture または PictureShape タイプの図形を見つける必要があります。 次に、SlidePicture.PictureFill.Picture.EmbedImage.Image.Save() メソッドまたは PictureShape.EmbedImage.Image.Save() メソッドを使用して、画像を画像ファイルに保存します。 詳細な手順は次のとおりです。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint プレゼンテーションをロードします。 Presentation.Slides[int] プロパティを使用して、インデックスで特定のスライドを取得します。 スライド上のすべての図形を反復処理します。 図形が SlidePicture または PictureShape タイプかを確認します。結果がtrueの場合は、SlidePicture.PictureFill.Picture.EmbedImage.Image.Save() または PictureShape.EmbedImage.Image.Save() メソッドを使用して画像を画像ファイルに保存します。 C# using Spire.Presentation; namespace ExtractImagesFromSlide { internal class Program { static void Main(string[] args) { //Presentation クラスのインスタンスを初期化する Presentation ppt = new Presentation(); //PowerPoint プレゼンテーションをロードする ppt.LoadFromFile(@"C:UsersAdministratorDesktopSample.pptx"); //2枚目のスライドを取得する ISlide slide = ppt.Slides[1]; int i = 0; //そのスライドのすべての図形を反復処理する foreach (IShape s in slide.Shapes) { //図形が SlidePicture タイプであるかどうかを確認する if (s is SlidePicture) { //画像を抽出する SlidePicture ps = s as SlidePicture; ps.PictureFill.Picture.EmbedImage.Image.Save(string.Format(@"C:UsersAdministratorDesktopSlideImages{0}.png", i)); i++; } //図形が PictureShape タイプであるかどうかを確認 if (s is PictureShape) { //画像を抽出する PictureShape ps = s as PictureShape; ps.EmbedImage.Image.Save(string.Format(@"SlideImages{0}.png", i)); i++; ppt.Dispose(); } } } } } 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。