Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 12, 2021 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/c98bfe5138c04e8695bbccd09229edd8 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c98bfe5138c04e8695bbccd09229edd8 to your computer and use it in GitHub Desktop.
Set Slide Background in PowerPoint Presentations using C++
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\Presentation2.pptx";
const String outputFilePath = u"OutputDirectory\\SetMasterSlideBackground_out.pptx";
// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Set the background color of the Master ISlide to Forest Green
presentation->get_Masters()->idx_get(0)->get_Background()->set_Type(BackgroundType::OwnBackground);
presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(FillType::Solid);
presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_ForestGreen());
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\Presentation2.pptx";
const String outputFilePath = u"OutputDirectory\\SetSlideBackground_out.pptx";
// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Set the background color of the first ISlide to Blue
presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType::OwnBackground);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(FillType::Solid);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue());
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\Presentation2.pptx";
const String outputFilePath = u"OutputDirectory\\SetSlideGradientBackground_out.pptx";
// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Apply Gradient effect to the Background
presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType::OwnBackground);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(FillType::Gradient);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_GradientFormat()->set_TileFlip(TileFlip::FlipBoth);
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\Presentation2.pptx";
const String imageFilePath = u"SourceDirectory\\Images\\Tulips.jpg";
const String outputFilePath = u"OutputDirectory\\SetSlideImageBackground_out.pptx";
// Load the presentation file
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Set background properties
presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType::OwnBackground);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(FillType::Picture);
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode(PictureFillMode::Stretch);
// Get the picture
auto bitmap = MakeObject<System::Drawing::Bitmap>(imageFilePath);
// Add image to presentation's images collection
SharedPtr<IPPImage> imgx = presentation->get_Images()->AddImage(bitmap);
// Set the image as the background
presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image(imgx);
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment