How to extract all images from a specific slide

We usually add lots of images to make the PowerPoint presentation obvious and attractive. With Spire.Presentation, we can easily extract the text from the presentation slides, and we can extract all the images from the whole PowerPoint document file. From Spire.Presentation v 2.5.21, now it supports to get all images from a single specific slide. This article will demonstrate you how to extract all images from a slide.

Firstly, please view the whole PowerPoint slides with images and these images need to be extracted.

How to extract all images from a specific slide

Note: Before Start, please download the latest version of Spire.Presentation and add Spire.Presentaion.dll in the bin folder as the reference of Visual Studio.

Here come to the code snippet of how to extract the images from a slide.

Step 1: Create a Presentation document and load from file.

Presentation PPT = new Presentation();
PPT.LoadFromFile("sample.pptx");

Step 2: Get the pictures on the first slide and save them to image file.

int i = 0;
foreach (IShape s in PPT.Slides[0].Shapes)
{
    if (s is SlidePicture)
    {
        SlidePicture ps = s as SlidePicture;
        ps.PictureFill.Picture.EmbedImage.Image.Save(string.Format("{0}.png", i));
        i++;
    }
    if (s is PictureShape)
    {
        PictureShape ps = s as PictureShape;
        ps.EmbedImage.Image.Save(string.Format("{0}.png", i));
        i++;
    }
}

Effective screenshots of the extracted images:

How to extract all images from a specific slide

Full codes:

static void Main(string[] args)
 {
     Presentation PPT = new Presentation();
     PPT.LoadFromFile("sample.pptx");

     int i = 0;
     foreach (IShape s in PPT.Slides[0].Shapes)
     {
         if (s is SlidePicture)
         {
             SlidePicture ps = s as SlidePicture;
             ps.PictureFill.Picture.EmbedImage.Image.Save(string.Format("{0}.png", i));
             i++;
         }
         if (s is PictureShape)
         {
             PictureShape ps = s as PictureShape;
             ps.EmbedImage.Image.Save(string.Format("{0}.png", i));
             i++;
         }
     }
 }