画像は、視聴者にすぐに気づかれ、記憶されやすいので、情報を伝える上で非常に効果的です。PowerPoint に画像を追加する方法については、魅力的なプレゼンテーションを作成し、視聴者に良い印象を与えるのに役立ちます。この記事では、Spire.Presentation for .NET を使用して、C# および VB.NET で PowerPoint に画像を追加する方法を示します。 スライドに画像を追加する スライドマスターに画像を追加する Spire.Presentation for.NET をインストールします まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを.NETプロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。 PM> Install-Package Spire.Presentation C# および VB.NET でスライドに画像を追加する Spire.Presentation が提供する ISlide.Shapes.AppendEmbedImage() メソッドは、特定のスライドに画像の追加をサポートします。詳細な手順は次のとおりです。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。 Presentation.Slides[int] プロパティを使用して特定のスライドをインデックスで取得します。 ISlide.Shapes.AppendEmbedImage() メソッドを使用してスライドに画像を追加します。 Presentation.SaveToFile() メソッドを使用して結果ドキュメントを保存します。 C# VB.NET using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace AddImageToSlide { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Input.pptx"); //最初のスライドを取得する ISlide slide = presentation.Slides[0]; //スライドに画像を挿入する string ImageFile2 = @"Image.png"; RectangleF rect = new RectangleF(presentation.SlideSize.Size.Width / 2 - 340, 220, 180, 180); IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect); image.Line.FillType = FillFormatType.None; //結果ドキュメントを保存する presentation.SaveToFile("InsertImageIntoSlide.pptx", FileFormat.Pptx2010); } } } Imports Spire.Presentation Imports Spire.Presentation.Drawing Imports System.Drawing Namespace AddImageToSlide Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Input.pptx") '最初のスライドを取得する Dim slide As ISlide = presentation.Slides(0) 'スライドに画像を挿入する Dim ImageFile2 = "Image.png" Dim rect As RectangleF = New RectangleF(presentation.SlideSize.Size.Width / 2 - 340, 220, 180, 180) Dim image As IEmbedImage = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect) image.Line.FillType = FillFormatType.None '結果ドキュメントを保存する presentation.SaveToFile("InsertImageIntoSlide.pptx", FileFormat.Pptx2010) End Sub End Class End Namespace C# および VB.NET でスライドマスターに画像を追加する スライド マスターは、スライドのテーマ、レイアウト、背景、色、フォントなどの情報を制御できる一番上のスライドです。 スライド マスターの情報は他のスライドにも影響します。 つまり、スライド マスターの情報を変更すると、後で追加されたスライドを含め、他のスライドもそれに応じて変更されます。 画像をすべてのスライドに表示する場合は、スライドマスターに追加できます。 Spire.Presentation が提供する IMasterSlide.Shapes.AppendEmbedImage() メソッドは、スライド マスターに画像の追加をサポートします。詳細な手順は次のとおりです。 Presentation クラスのインスタンスを初期化します。 Presentation.LoadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。 Presentation.Masters[int] プロパティを使用して、特定のスライドマスターをインデックスで取得します。 IMasterSlide.Shapes.AppendEmbedImage() メソッドを使用してスライドマスターに画像を追加します。 Presentation.SaveToFile() メソッドを使用して結果ドキュメントを保存します。 C# VB.NET using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace AddImageToSlideMaster { class Program { static void Main(string[] args) { //Presentationクラスのインスタンスを初期化する Presentation presentation = new Presentation(); //PowerPointドキュメントをロードする presentation.LoadFromFile(@"Sample.pptx"); //最初のスライドマスターを取得する IMasterSlide master = presentation.Masters[0]; //スライドマスターに画像を挿入する string image = @"logo.png"; RectangleF rect = new RectangleF(40, 40, 80, 80); IEmbedImage pic = master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rect); pic.Line.FillFormat.FillType = FillFormatType.None; //プレゼンテーションへに新しいスライドを追加する presentation.Slides.Append(); //結果ドキュメントを保存する presentation.SaveToFile("InsertImageIntoSlideMaster.pptx", FileFormat.Pptx2010); } } } Imports Spire.Presentation Imports Spire.Presentation.Drawing Imports System.Drawing Namespace AddImageToSlideMaster Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Presentationクラスのインスタンスを初期化する Dim presentation As Presentation = New Presentation() 'PowerPointドキュメントをロードする presentation.LoadFromFile("Sample.pptx") '最初のスライドマスターを取得する Dim master As IMasterSlide = presentation.Masters(0) 'スライドマスターに画像を挿入する Dim image = "logo.png" Dim rect As RectangleF = New RectangleF(40, 40, 80, 80) Dim pic As IEmbedImage = master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rect) pic.Line.FillFormat.FillType = FillFormatType.None 'プレゼンテーションへに新しいスライドを追加する presentation.Slides.Append() '結果ドキュメントを保存する presentation.SaveToFile("InsertImageIntoSlideMaster.pptx", FileFormat.Pptx2010) End Sub End Class End Namespace 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。