How to save image/picture from slide to file

I need to loop through the slide content and save the image/picture to file. So if the slide contains a jpeg image, I want to save that image to a file outside of the presentation.

Thanks,

John

Hi John,

Try this:

var presentation = PresentationDocument.Load("input.pptx");
foreach (var slide in presentation.Slides)
    foreach (var picture in slide.Content.Drawings.OfType<Picture>())
    {
        var pictureContent = picture.Fill.Data;
        string path = Path.GetRandomFileName() + "." + pictureContent.ContentType.ToString().ToLower();

        using (var pictureStream = pictureContent.Content.Open())
        using (var fileStream = File.Create(path))
            pictureStream.CopyTo(fileStream);
    }

I hope it helps.

Regards,
Mario