Search code examples
c#powerpointoffice-interop

C# Save PPT Shape (msoPicture) as Image w/ Office.Interop


I have a PPT slide deck with multiple images. I am iterating through each slide and each shape. I would like to save each shape of type msoPicture as an Image:

            foreach (PPT.Slide slide in pptDoc.Slides)
            {
                foreach (PPT.Shape shape in slide.Shapes)
                {
                    if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                    {

                        Image img;
                        //???? Save shape as image
                        img.Save(filename);
                    }
                }
            }

Solution

  • You can use the Shape.Export() method to create an image from an individual shape.

    For example like this:

    foreach (PPT.Slide slide in pptDoc.Slides)
    {
        foreach (PPT.Shape shape in slide.Shapes)
        {
            if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
            {
                shape.Export(filename, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG);
            }
        }
    }