While processing the PowerPoint presentations in a .NET application, you may need to extract content from the PPT slides. The content could be in the form of text and images. In the previous post, we have covered text extraction from PowerPoint slides. In this article, we will show you how to extract images from PowerPoint PPT or PPTX in C#.
- .NET API to Extract Images from Presentations
- Extract Images from a PPTX Presentation in C#
- Extract Images from Shapes
- Image Extraction from Slide Background
C# .NET API to Extract Images from PowerPoint PPT
For extracting images from PowerPoint PPT/PPTX, we will use Aspose.Slides for .NET. It is a feature-rich .NET API that allows you to create new presentations and manipulate the existing ones seamlessly. You can either download API’s DLL or install it using NuGet.
PM> Install-Package Aspose.Slides.NET
Extract Images from a PowerPoint PPT in C#
The following are the steps to extract all the images in a PPT presentation in C#.
- First, use Presentation class to load the PPT/PPTX file.
- Then, loop through all the images in the presentation using Presentation.Images collection.
- Finally, get type and format of each image and save it.
The following code sample shows how to extract images from a PowerPoint PPT in C#.
Extract Images from Shapes in a PPT
In various cases, you may need to extract images from the shape objects only. This can be achieved by following the steps below.
- First, use Presentation class to load the presentation file.
- Then, use Presentation.Slides collection to loop through slides.
- For each slide, access its shapes using ISlide.Shapes collection.
- Perform the following steps for each shape in the collection:
The following code sample shows how to extract images from shapes in a PPT using C#.
Extract Images from Slide Backgrounds in C#
Another possible scenario could be extracting images that are used only as slide backgrounds. The following steps show how to extract slide background images in C#.
- First, load the PPT/PPTX file using Presentation class.
- Then, loop through the slides in the presentation using Presentation.Slides collection.
- For each slide, perform the following steps:
- Check if slide has a background image using ISlide.Background.FillFormat.FillType property.
- If the background has picture then extract image using Background.FillFormat.PictureFillFormat.Picture.Image property.
- Check if the layout slide has background image using LayoutSlide.Background.FillFormat.FillType property.
- If layout slide’s background is filled with a picture then extract it using ISlide.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image property.
- Finally, save the extracted image as a file.
The following code sample shows how to extract images from slide backgrounds in a PPT in C#.
We have used the method GetImageFormat in all of the above code snippets. This method returns the appropriate image format for the provided type. The implementation of this method is given below.
Get a Free License
You can get a free temporary license to use Aspose.Slides for .NET without evaluation limitations.
In this article, you have learned how to extract images from PowerPoint PPT/PPTX in C#. With the help of code samples, we have demonstrated how to extract images from shapes and slide backgrounds. You can explore more about Aspose.Slides for .NET by visiting the documentation. Also, you can ask your questions via our forum.