C#/VB.NET: Add Images to PowerPoint Documents

Images are very effective in communicating information because they can be quickly noticed and easily remembered by the audience. Knowing how to add images to PowerPoint can help you create an appealing presentation and make a good impression on your audience. In this article, you will learn how to add images to PowerPoint documents in C# and VB.NET using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Add an Image to a Slide in C# and VB.NET

Spire.Presentation offers the ISlide.Shapes.AppendEmbedImage() method to add an image to a specific slide. The following are the main steps:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get a specific slide by its index through Presentation.Slides[int] property.
  • Add an image to the slide using ISlide.Shapes.AppendEmbedImage() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace AddImageToSlide
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of Presentation class
            Presentation presentation = new Presentation();
            //Load a PowerPoint document
            presentation.LoadFromFile(@"Input.pptx");

            //Get the first slide
            ISlide slide = presentation.Slides[0];
           
            //Insert an image into the slide
            string ImageFile2 = @"Image.png";
            RectangleF rect = new RectangleF(presentation.SlideSize.Size.Width / 2 - 280, 140, 120, 120);
            IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect);
            image.Line.FillType = FillFormatType.None;

            //Save the result document
            presentation.SaveToFile("InsertImageIntoSlide.pptx", FileFormat.Pptx2010);
        }
    }
}

C#/VB.NET: Add Images to PowerPoint Documents

Add an Image to a Slide Master in C# and VB.NET

A slide master is the top slide that controls all information about the theme, layout, background, color and fonts, which will be inherited by other slides in the presentation. In other words, when you modify the style of the slide master, every slide in the presentation will be changed accordingly, including the ones added later. If you want an image to appear on all your slides, you can add it to one place - the slide master.

Spire.Presentation offers the IMasterSlide.Shapes.AppendEmbedImage() method to add an image to a slide master. The following are the detailed steps:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get a specific slide master in the document by its index through Presentation.Masters[int] property.
  • Add an image to the slide using IMasterSlide.Shapes.AppendEmbedImage() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace AddImageToSlideMaster
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation presentation = new Presentation();
            //Load a PowerPoint document
            presentation.LoadFromFile(@"Sample.pptx");

            //Get the first slide master in the document
            IMasterSlide master = presentation.Masters[0];
            
            //Insert an image into the slide master
            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;

            //Add a new slide to the presentation
            presentation.Slides.Append();

            //Save the result document
            presentation.SaveToFile("InsertImageIntoSlideMaster.pptx", FileFormat.Pptx2010);
        }
    }
}

C#/VB.NET: Add Images to PowerPoint Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.