Get the Entire Presentation Slide Background as an Image
Contents
[
Hide
]
In PowerPoint presentations, the slide background can consist of many elements. In addition to the image set as the slide background, the final background can be influenced by the presentation theme, color scheme, and the shapes placed on the master slide and layout slide.
Aspose.Slides for C++ does not provide a simple method to extract the entire presentation slide background as an image, but you can follow the steps below to do this:
- Load the presentation using the Presentation class.
- Get the slide size from the presentation.
- Select a slide.
- Create a temporary presentation.
- Set the same slide size in the temporary presentation.
- Clone the selected slide into the temporary presentation.
- Delete the shapes from the cloned slide.
- Convert the cloned slide to an image.
The following code example extracts the entire presentation slide background as an image.
auto slideIndex = 0;
auto imageScale = 1;
auto presentation = System::MakeObject<Presentation>(u"sample.pptx");
auto slideSize = presentation->get_SlideSize()->get_Size();
auto slide = presentation->get_Slides()->idx_get(slideIndex);
auto tempPresentation = System::MakeObject<Presentation>();
auto slideWidth = slideSize.get_Width();
auto slideHeight = slideSize.get_Height();
tempPresentation->get_SlideSize()->SetSize(slideWidth, slideHeight, SlideSizeScaleType::DoNotScale);
auto clonedSlide = tempPresentation->get_Slides()->AddClone(slide);
clonedSlide->get_Shapes()->Clear();
auto background = clonedSlide->GetImage(imageScale, imageScale);
background->Save(u"output.png", ImageFormat::Png);
tempPresentation->Dispose();
presentation->Dispose();