PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

Microsoft PowerPoint 提供了根据您的需要设置 PowerPoint 幻灯片背景的选项。在某些情况下,您可能需要以编程方式设置 PowerPoint 幻灯片的背景。为此,本文将教您如何使用 C++ 设置 PowerPoint 幻灯片的背景。在本文中,您将学习如何设置纯色、渐变和图像背景。

Microsoft PowerPoint 提供了根据您的需要设置 PowerPoint 幻灯片背景的选项。在某些情况下,您可能需要以编程方式设置 PowerPoint 幻灯片的背景。为此,本文将教您如何使用 C++ 设置 PowerPoint 幻灯片的背景。在本文中,您将学习如何设置纯色、渐变和图像背景。

>>你可以点击这里下载Aspose.Slides 最新版测试体验。

  • 用于在 PowerPoint 演示文稿中设置幻灯片背景的 C++ API
  • 使用 C++ 设置普通幻灯片的背景颜色
  • 使用 C++ 设置母版幻灯片的背景颜色
  • 使用 C++ 设置幻灯片的渐变背景颜色
  • 使用 C++ 将图像设置为幻灯片背景

用于在 PowerPoint 演示文稿中设置幻灯片背景的 C++ API

我们将使用 Aspose.Slides for C++  API 在 Powerpoint 演示文稿中设置幻灯片背景。它是一个强大且功能丰富的 API,支持创建、阅读和修改 PowerPoint 文件,而无需其他软件。

使用 C++ 设置普通幻灯片的背景颜色

以下是使用C++设置普通幻灯片背景颜色的步骤。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType 值)方法设置背景类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(Aspose::Slides::FillType 值)方法设置填充类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color 值)方法设置颜色。
  • 最后,使用Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存 PowerPoint 文件 。

以下示例代码展示了如何使用 C++ 设置普通幻灯片的背景颜色。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\Presentation2.pptx";const String outputFilePath = u"OutputDirectory\SetSlideBackground_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Set the background color of the first ISlide to Bluepresentation->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 Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

下面给出的是设置背景颜色之前的幻灯片图像。

PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

下面是设置背景色后的幻灯片图片。

PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

使用 C++ 设置母版幻灯片的背景颜色

为了设置母版幻灯片的背景颜色,请按照以下步骤操作。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Masters()->idx_get(0)->get_Background()-set_Type(BackgroundType 值)方法设置背景类型。
  • 使用Presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(Aspose::Slides::FillType 值)方法设置填充类型。
  • 使用Presentation->get_Masters()->idx_get(0)->get_Background()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color 值)方法设置颜色。
  • 最后,使用Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存 PowerPoint 文件 。

以下示例代码显示了如何使用 C++ 设置母版幻灯片的背景颜色。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\Presentation2.pptx";const String outputFilePath = u"OutputDirectory\SetMasterSlideBackground_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Set the background color of the Master ISlide to Forest Greenpresentation->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 Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

使用 C++ 设置幻灯片的渐变背景颜色

除了使用纯色,您还可以对 PowerPoint 幻灯片应用渐变背景色。为了实现这一点,请按照以下步骤操作。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType 值)方法设置背景类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(Aspose::Slides::FillType 值)方法设置填充类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_GradientFormat()->set_TileFlip(Aspose::Slides::TileFlip 值)方法设置渐变格式。
  • 最后,使用Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存 PowerPoint 文件 。

以下示例代码展示了如何使用 C++ 设置幻灯片的渐变背景颜色。

// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\Presentation2.pptx";const String outputFilePath = u"OutputDirectory\SetSlideGradientBackground_out.pptx";// Load the presentation fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Apply Gradient effect to the Backgroundpresentation->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 Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

使用 C++ 将图像设置为幻灯片背景

要将图像用作幻灯片背景,请按照以下步骤操作。

  • 首先,使用Presentation 类加载 PowerPoint 文件 。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->set_Type(BackgroundType 值)方法设置背景类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->set_FillType(Aspose::Slides::FillType 值)方法设置填充类型。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode(Aspose::Slides::PictureFillMode 值)方法设置图片填充模式。
  • 使用Bitmap类加载图像。
  • 使用Presentation->get_Images()->AddImage (System::SharedPtr<System::Drawing::Image> image)方法将图像添加到演示文稿的图像集合中。
  • 使用Presentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image (System::SharedPtr<IPPImage>值)方法。
  • 最后,使用Presentation->Save(System::String fname, Export::SaveFormat format) 方法保存 PowerPoint 文件 。

以下示例代码显示了如何使用 C++ 将图像设置为幻灯片背景。

// File pathsconst 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 fileauto presentation = System::MakeObject<Presentation>(sourceFilePath);// Set background propertiespresentation->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 pictureauto bitmap = MakeObject<System::Drawing::Bitmap>(imageFilePath);// Add image to presentation's images collectionSharedPtr<IPPImage> imgx = presentation->get_Images()->AddImage(bitmap);// Set the image as the backgroundpresentation->get_Slides()->idx_get(0)->get_Background()->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image(imgx);// Save Presentationpresentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);

PPT处理控件Aspose.Slides功能演示:使用 C++ 在 PowerPoint 演示文稿中设置幻灯片背景

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年9月23日
下一篇 2021年9月23日

相关推荐

发表回复

登录后才能评论