Insert image in PowerPoint document

Image can add interest and take effect to your PPT documents. Suppose you've demonstrated your design for your boss in order to acquire his/her recognition. Just using words describe, you cannot present a perfect design for your boss, because that slide of text looks indistinct, dull and unpersuasive. You need image to embellish your design make it more persuasive.

Spire.Presentation for .NET, a reliable .NET PPT component, enables you to generate, read, edit, convert even print your PPT documents without installing Microsoft PowerPoint on your machine. Using Spire.Presentation for .NET, you also can insert image in your PPT document with C#. Please see the target PPT document with image as below picture:

Insert image in PPT document

This guide will introduce the method to insert image in your PPT document with C#, VB.NET via Spire.Presentation for .NET.

The main steps of method are:

Step 1: Create ppt document.

Presentation presentation = new Presentation();

Step 2: Insert image to PPT

string ImageFile2 = @" PPT.png";
RectangleF rect=new RectangleF(50, 100, 600, 245);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

Step 3: Add text to appended shape and save the document.

RectangleF rect1=new RectangleF(30, 40, 630, 50);
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect1);
shape.TextFrame.Text = "The sample demonstrates how to insert a image into a slide.";
presentation.SaveToFile("InsertPicture.PPTx", FileFormat.PPTx2010);

Download and install Spire.Presentation for .NET and use below code to experience this method to insert image in PPT document.

The full code:

[C#]
using System;
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Drawing;

namespace InsertImageC
{
    class Program
    {
        static void Main(string[] args)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //insert image to PPT
            string ImageFile2 = @" PPT.png";
            RectangleF rect=new RectangleF(50, 100, 600, 245);
            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;	

            //append new shape
            RectangleF rect1=new RectangleF(30, 40, 630, 50);
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect1);
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;

            //add text to shape
            shape.TextFrame.Text = "The sample demonstrates how to insert a image into a slide.";
            TextRange textRange = shape.TextFrame.TextRange;

            //set the Font
            textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange.Fill.SolidColor.Color = Color.Black;
            textRange.LatinFont = new TextFont("Arial Black");

            //save the document
            presentation.SaveToFile("InsertPicture.PPTx", FileFormat.PPTx2010);
            System.Diagnostics.Process.Start("InsertPicture.PPTx");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Presentation
Imports System.Drawing.Printing
Imports Spire.Presentation.Drawing
Module Module1

    Sub Main()
        'create PPT document
        Dim presentation As New Presentation()

       'insert image to PPT
        Dim ImageFile2 As String = " PPT.png"
        Dim rect As RectangleF= New RectangleF(50, 100, 600, 245)
        presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2,)
        presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite

        'append new shape
        Dim rect1 As RectangleF= New RectangleF(30, 40, 630, 50)
        Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, rect1)
        shape.Fill.FillType = FillFormatType.None
        shape.ShapeStyle.LineColor.Color = Color.White

        'add text to shape
        shape.TextFrame.Text = "The sample demonstrates how to insert a image into a slide."
        Dim textRange As TextRange = shape.TextFrame.TextRange

        'set the Font
        textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid
        textRange.Fill.SolidColor.Color = Color.Black
        textRange.LatinFont = New TextFont("Arial Black")

        'save the document
        presentation.SaveToFile("InsertPicture.PPTx", FileFormat.PPTx2010)
        System.Diagnostics.Process.Start("InsertPicture.PPTx")
    End Sub
End Module

If you couldn't successfully use the Spire.presentation, please refer the Spire.Presentation Quick Start which can guide you quickly use the Spire.presentation.