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