チュートリアル

簡単にライブラリーを使用するためのチュートリアルコレクション

チュートリアル»pptnetimageandshape

Displaying items by tag: pptnetimageandshape

画像は PowerPoint で最も一般的な要素の 1 つです。 場合によっては、特定のスライドまたはプレゼンテーション全体から画像を抽出したい場合があります。 たとえば、それらの画像を別のプレゼンテーションで再利用したいとします。この記事では、Spire.Presentation for .NET を使用して 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:\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();
        }
    }
}

C#:PowerPoint プレゼンテーションから画像を抽出する

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:\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();
                }
            }
        }
    }
}

C#:PowerPoint プレゼンテーションから画像を抽出する

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 画像と図形
Tagged under

PowerPoint の図形は、スライド内で重要な情報やキーメッセージを強調するための優れたツールです。図形を使用することで、効果的に注意を引き、視覚的な手がかりを作成し、視聴者を積極的に関与させることができます。戦略的に図形を追加することで、PowerPoint プレゼンテーションの影響力を高め、観客に長く残る印象を与えることができます。この記事では、Spire.Presentation for .NET を使用して C# で PowerPoint プレゼンテーションにさまざまなタイプの図形を追加する方法を示します。

Spire.Presentation for .NET をインストールします

まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。

PM> Install-Package Spire.Presentation

C# で PowerPoint プレゼンテーションに図形を追加する

Spire.Presentation for .NET によって提供される ISlide.Shapes.AppendShape(ShapeType shapeType, RectangleF rectangle) メソッドを使用することで、PowerPoint プレゼンテーションに四角形、三角形、矢印、楕円などのさまざまな形状を追加することができます。詳細な手順は次のとおりです。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.LoadFromFile(string fileName) メソッドを使用して、 PowerPoint プレゼンテーションをロードします。
  • Presentation.Slides[int index] プロパティを使用して、特定のスライドを取得します。
  • ISlide.Shapes.Append(ShapeType shapeType, RectangleF rectangle) メソッドを使用して、さまざまな種類の図形をスライドに追加します。
  • そして、図形のスタイルを設定します。
  • Presentation.SaveToFile(string fileName, FileFormat fileFormat) メソッドを使用して 、PowerPoint プレゼンテーションを保存します。
  • C#
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();
        }
    }
}

C#:PowerPoint プレゼンテーションに図形を追加する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 画像と図形
Tagged under

画像は、視聴者にすぐに気づかれ、記憶されやすいので、情報を伝える上で非常に効果的です。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:PowerPoint に画像を追加する方法

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

C#/VB.NET:PowerPoint に画像を追加する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 画像と図形
Tagged under