Microsoft PowerPoint provides the option to set the background of PowerPoint slides according to your needs. There might be situations where you need to set the background of PowerPoint slides programmatically. To that end, this article will teach you how to set the background of PowerPoint slides using C++. Specifically, you will learn how to set solid color, gradient, and image backgrounds.
- C++ API for Setting Slide Background in PowerPoint Presentations
- Set Background Color of Normal Slides using C++
- Set Background Color of Master Slide using C++
- Setting Gradient Background Color of Slides using C++
- Set Image as Slide Background using C++
C++ API for Setting Slide Background in PowerPoint Presentations
We will use the Aspose.Slides for C++ API to set slide background in Powerpoint presentations. It is a robust and feature-rich API that supports creating, reading, and modifying PowerPoint files without requiring additional software. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Slides.Cpp
Set Background Color of Normal Slides using C++
The following are the steps to set the background color of a normal slide using C++.
- Firstly, load the PowerPoint file using the Presentation class.
- Set the background type using the Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type (BackgroundType value) method.
- Set the fill type using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType (Aspose::Slides::FillType value) method.
- Set the color using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color (System::Drawing::Color value) method.
- Finally, save the PowerPoint file using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the background color of normal slides using C++.
Given below is the image of the slide before setting the background color.
The following is the image of the slide after setting the background color.
Set Background Color of Master Slide using C++
In order to set the background color of the Master slide, follow the steps given below.
- Firstly, load the PowerPoint file using the Presentation class.
- Set the background type using the Presentation->get_Masters()->idx_get(0)->get_Background()-set_Type (BackgroundType value) method.
- Set the fill type using the Presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType (Aspose::Slides::FillType value) method.
- Set the color using the Presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color ( System::Drawing::Color value) method.
- Finally, save the PowerPoint file using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the background color of the master slide using C++.
Setting Gradient Background Color of Slides using C++
Instead of using solid colors, you can also apply gradient background color to PowerPoint slides. In order to achieve that, please follow the steps given below.
- Firstly, load the PowerPoint file using the Presentation class.
- Set the background type using the Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type (BackgroundType value) method.
- Set the fill type using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType (Aspose::Slides::FillType value) method.
- Set the gradient format using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_GradientFormat()->set_TileFlip (Aspose::Slides::TileFlip value) method.
- Finally, save the PowerPoint file using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the gradient background color of slides using C++.
Set Image as Slide Background using C++
In order to use an image as a slide background, follow the step given below.
- Firstly, load the PowerPoint file using the Presentation class.
- Set the background type using the Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type (BackgroundType value) method.
- Set the fill type using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType (Aspose::Slides::FillType value) method.
- Set the picture fill mode using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode (Aspose::Slides::PictureFillMode value) method.
- Load the image using the Bitmap class.
- Add the image to the presentation’s image collection using the Presentation->get_Images()->AddImage (System::SharedPtr<System::Drawing::Image> image) method.
- Set the image as background using the Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image (System::SharedPtr<IPPImage> value) method.
- Finally, save the PowerPoint file using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set an image as a slide background using C++.
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to set the background of PowerPoint slides using C++. Specifically, you have learned how to set solid color, gradient, and image backgrounds using Aspose.Slides for C++ API. It is a powerful API that provides a bunch of additional features for working with PowerPoint files. You can explore the API in detail by visiting the official documentation. In case of any queries, please feel free to reach us at our free support forum.