How to Export Shapes as Images in PowerPoint in C#, VB.NET

It is pretty easy in MS PowerPoint to export a certain shape as image with following two steps:

  • 1. Select the object shape
  • 2. From the right-click menu select Save as Picture

However, Spire.Presentation also provides easy method for programmers to save shapes out of slides. In the following section, we’ll introduce how to export shapes as images via Spire.Presentation with an example.

Test File:

As is shown in the screenshot, the sample file for testing contains several shapes on the first slide.

How to Export Shapes as Images in PowerPoint in C#, VB.NET

Code Snippet for Exporting Shape as Image:

Step 1: Initialize a new instance of Presentation class and load the test file from disk.

Presentation ppt = new Presentation();
ppt.LoadFromFile("test.pptx");

Step 2: Use for loop to traverse every shape in the slide. Call ShapeList.SaveAsImage(int shapeIndex) to save shape as image, then save this image to the specified file in the specified format.

for (int i = 0; i < ppt.Slides[0].Shapes.Count; i++)
{
    Image image = ppt.Slides[0].Shapes.SaveAsImage(i);
    image.Save(String.Format("Picture-{0}.png", i), System.Drawing.Imaging.ImageFormat.Png);
}

Output:

Picture-0

How to Export Shapes as Images in PowerPoint in C#, VB.NET

Picture-1

How to Export Shapes as Images in PowerPoint in C#, VB.NET

Entire Code:

[C#]
Presentation ppt = new Presentation();
ppt.LoadFromFile("test.pptx");

for (int i = 0; i < ppt.Slides[0].Shapes.Count; i++)
{
    Image image = ppt.Slides[0].Shapes.SaveAsImage(i);
    image.Save(String.Format("Picture-{0}.png", i), System.Drawing.Imaging.ImageFormat.Png);
}
[VB.NET]
Dim ppt As New Presentation()
ppt.LoadFromFile("test.pptx")

For i As Integer = 0 To ppt.Slides(0).Shapes.Count - 1
	Dim image As Image = ppt.Slides(0).Shapes.SaveAsImage(i)
	image.Save([String].Format("Picture-{0}.png", i), System.Drawing.Imaging.ImageFormat.Png)
Next