原創|使用教程|編輯:張瑩心|2021-10-26 10:13:49.763|閱讀 300 次
概述:Microsoft PowerPoint 提供了根據您的需要設置 PowerPoint 幻燈片背景的選項。在某些情況下,您可能需要以編程方式設置 PowerPoint 幻燈片的背景。為此,本文將教您如何使用 C++ 設置 PowerPoint 幻燈片的背景。在本文中,您將學習如何設置純色、漸變和圖像背景。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Microsoft PowerPoint 提供了根據您的需要設置 PowerPoint 幻燈片背景的選項。在某些情況下,您可能需要以編程方式設置 PowerPoint 幻燈片的背景。為此,本文將教您如何使用 C++ 設置 PowerPoint 幻燈片的背景。在本文中,您將學習如何設置純色、漸變和圖像背景。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
我們將使用 Aspose.Slides for C++ API 在 Powerpoint 演示文稿中設置幻燈片背景。它是一個強大且功能豐富的 API,支持創建、閱讀和修改 PowerPoint 文件,而無需其他軟件。
以下是使用C++設置普通幻燈片背景顏色的步驟。
以下示例代碼展示了如何使用 C++ 設置普通幻燈片的背景顏色。
// 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);
下面給出的是設置背景顏色之前的幻燈片圖像。
下面是設置背景色后的幻燈片圖片。
為了設置母版幻燈片的背景顏色,請按照以下步驟操作。
以下示例代碼顯示了如何使用 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);
除了使用純色,您還可以對 PowerPoint 幻燈片應用漸變背景色。為了實現這一點,請按照以下步驟操作。
// 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);
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn