チュートリアル
簡単にライブラリーを使用するためのチュートリアルコレクション
画像は PowerPoint で最も一般的な要素の 1 つです。 場合によっては、特定のスライドまたはプレゼンテーション全体から画像を抽出したい場合があります。 たとえば、それらの画像を別のプレゼンテーションで再利用したいとします。この記事では、Spire.Presentation for .NET を使用して C# で PowerPoint プレゼンテーションから画像を抽出する方法を示します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
PowerPoint 全体から画像を抽出するには、Presentation.Images プロパティを使用してプレゼンテーション内のすべての画像のコレクションを取得します。そして、コレクションを反復処理して ImageCollection[int].Image.Save() メソッドを使用して、各画像を画像ファイルに保存します。詳細な手順は次のとおりです。
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:\Users\Administrator\Desktop\Sample.pptx");
//プレゼンテーションの画像コレクションを取得する
ImageCollection imageCollection = ppt.Images;
//コレクション内の画像を反復処理する
for (int i = 0; i < imageCollection.Count; i++)
{
//画像を抽出する
imageCollection[i].Image.Save(string.Format(@"C:\Users\Administrator\Desktop\Images\Image{0}.png", i));
}
ppt.Dispose();
}
}
}
特定のスライドから画像を抽出するには、スライドのすべての図形を反復処理し、SlidePicture または PictureShape タイプの図形を見つける必要があります。 次に、SlidePicture.PictureFill.Picture.EmbedImage.Image.Save() メソッドまたは PictureShape.EmbedImage.Image.Save() メソッドを使用して、画像を画像ファイルに保存します。 詳細な手順は次のとおりです。
using Spire.Presentation;
namespace ExtractImagesFromSlide
{
internal class Program
{
static void Main(string[] args)
{
//Presentation クラスのインスタンスを初期化する
Presentation ppt = new Presentation();
//PowerPoint プレゼンテーションをロードする
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.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:\Users\Administrator\Desktop\Slide\Images{0}.png", i));
i++;
}
//図形が PictureShape タイプであるかどうかを確認
if (s is PictureShape)
{
//画像を抽出する
PictureShape ps = s as PictureShape;
ps.EmbedImage.Image.Save(string.Format(@"Slide\Images{0}.png", i));
i++;
ppt.Dispose();
}
}
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
PowerPoint の図形は、スライド内で重要な情報やキーメッセージを強調するための優れたツールです。図形を使用することで、効果的に注意を引き、視覚的な手がかりを作成し、視聴者を積極的に関与させることができます。戦略的に図形を追加することで、PowerPoint プレゼンテーションの影響力を高め、観客に長く残る印象を与えることができます。この記事では、Spire.Presentation for .NET を使用して C# で PowerPoint プレゼンテーションにさまざまなタイプの図形を追加する方法を示します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
Spire.Presentation for .NET によって提供される ISlide.Shapes.AppendShape(ShapeType shapeType, RectangleF rectangle) メソッドを使用することで、PowerPoint プレゼンテーションに四角形、三角形、矢印、楕円などのさまざまな形状を追加することができます。詳細な手順は次のとおりです。
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddShapes
{
internal class Program
{
static void Main(string[] args)
{
//Presentationクラスのインスタンスを初期化します
Presentation presentation = new Presentation();
//PowerPointプレゼンテーションをロードします
presentation.LoadFromFile("Input.pptx");
//最初のスライドを取得します
ISlide slide = presentation.Slides[0];
//スライドに三角形の図形を追加する
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Triangle, new RectangleF(185, 130, 100, 100));
//図形を塗りつぶします
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.LightGreen;
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.White;
//スライドに楕円の図形を追加します
shape = slide.Shapes.AppendShape(ShapeType.Ellipse, new RectangleF(370, 130, 150, 100));
//図形を画像で塗りつぶします
string picUrl = @"background.jpg";
shape.Fill.FillType = FillFormatType.Picture;
shape.Fill.PictureFill.Picture.Url = picUrl;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.CornflowerBlue;
//スライドにハートの図形を追加します
shape = slide.Shapes.AppendShape(ShapeType.Heart, new RectangleF(600, 130, 130, 100));
//図形にテキストを追加します
shape.TextFrame.Text = "Heart";
//図形を塗りつぶします
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Red;
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.LightGray;
//スライドに五角星の図形を追加します
shape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(160, 270, 150, 150));
//図形をグラデーションで塗りつぶします
shape.Fill.FillType = FillFormatType.Gradient;
shape.Fill.SolidColor.Color = Color.Black;
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.White;
//スライドに長方形の図形を追加します
shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(400, 290, 100, 120));
//図形を塗りつぶします
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Pink;
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.LightGray;
//スライドに矢印の図形を追加します
shape = slide.Shapes.AppendShape(ShapeType.BentUpArrow, new RectangleF(600, 300, 150, 100));
//図形をグラデーションで塗りつぶします
shape.Fill.FillType = FillFormatType.Gradient;
shape.Fill.Gradient.GradientStops.Append(1f, KnownColors.Olive);
shape.Fill.Gradient.GradientStops.Append(0, KnownColors.PowderBlue);
//図形のアウトラインの色を設定します
shape.ShapeStyle.LineColor.Color = Color.White;
//結果文書を保存します
presentation.SaveToFile("AddShapes.pptx", FileFormat.Pptx2010);
presentation.Dispose();
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
画像は、視聴者にすぐに気づかれ、記憶されやすいので、情報を伝える上で非常に効果的です。PowerPoint に画像を追加する方法については、魅力的なプレゼンテーションを作成し、視聴者に良い印象を与えるのに役立ちます。この記事では、Spire.Presentation for .NET を使用して、C# および VB.NET で PowerPoint に画像を追加する方法を示します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを.NETプロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
Spire.Presentation が提供する ISlide.Shapes.AppendEmbedImage() メソッドは、特定のスライドに画像の追加をサポートします。詳細な手順は次のとおりです。
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
スライド マスターは、スライドのテーマ、レイアウト、背景、色、フォントなどの情報を制御できる一番上のスライドです。 スライド マスターの情報は他のスライドにも影響します。 つまり、スライド マスターの情報を変更すると、後で追加されたスライドを含め、他のスライドもそれに応じて変更されます。 画像をすべてのスライドに表示する場合は、スライドマスターに追加できます。
Spire.Presentation が提供する IMasterSlide.Shapes.AppendEmbedImage() メソッドは、スライド マスターに画像の追加をサポートします。詳細な手順は次のとおりです。
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 日間有効な一時ライセンスを取得してください。