This demo uses the DevExpress Presentation API to extract images from presentation slides. You can use the predefined sample file or upload your own presentation. To do the latter, select Upload a File in the file selection drop-down menu.
In the Extraction Settings panel, specify the slide range from which to extract images. Use the Extract Images as... dropdown button to select the image output format, extract images, and download the result.
Sample document
Sample.pptx
Extraction Settings
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
IReadOnlyList<Stream> ExtractImages(Stream inputStream, DXImageFormat imageFormat, List<int> slideRange) {
using var presentation = new Presentation(inputStream);
var imageStreams = new List<Stream>();
bool shouldExportFromAllSlides = slideRange.Count == 0;
for(int i = 0; i < presentation.Slides.Count; i++) {
if(shouldExportFromAllSlides || slideRange.Contains(i)) {
var slide = presentation.Slides[i];
foreach(var shape in slide.Shapes)
ExtractShapeImages(shape, imageStreams, imageFormat);
}
}
return imageStreams.AsReadOnly();
}
void ExtractShapeImages(ShapeBase shape, IList<Stream> imageStreams, DXImageFormat imageFormat) {
switch(shape) {
case PictureShape pictureShape:
var officeImage = pictureShape.Image as OfficeImage;
var dxImage = officeImage?.DXImage;
if(dxImage != null) {
var imgStream = new MemoryStream();
dxImage.Save(imgStream, imageFormat);
imgStream.Position = 0;
imageStreams.Add(imgStream);
}
break;
case GroupShape groupShape:
foreach(var innerShape in groupShape.Shapes)
ExtractShapeImages(innerShape, imageStreams, imageFormat);
break;
default:
break;
}
}