Slide Transition

Add Slide Transition

To make it easier to understand, we have demonstrated the use of Aspose.Slides for C++ to manage simple slide transitions. Developers can not only apply different slide transition effects on the slides, but also customize the behavior of these transition effects. To create a simple slide transition effect, follow the steps below:

  1. Create an instance of Presentation class.
  2. Apply a Slide Transition Type on the slide from one of the transition effects offered by Aspose.Slides for C++ through TransitionType enum.
  3. Write the modified presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SimpleSlideTransitions.pptx";
const String outPath = u"../out/SimpleSlideTransitions.pptx";
// Instantiate Presentation class
SharedPtr<Presentation>pres = MakeObject<Presentation>(templatePath);
// Apply circle type transition on slide 1
pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Circle);
// Apply comb type transition on slide 2
pres->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Comb);
// Write the presentation to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Add Advanced Slide Transition

In the above section, we just applied a simple transition effect on the slide. Now, to make that simple transition effect even better and controlled, please follow the steps below:

  1. Create an instance of Presentation class.
  2. Apply a Slide Transition Type on the slide from one of the transition effects offered by Aspose.Slides for C++
  3. You can also set the transition to Advance On Click, after a specific time period or both.
  4. If the slide transition is enabled to Advance On Click, the transition will only advance when someone will click the mouse. Moreover, if the Advance After Time property is set, the transition will advance automatically after the specified advance time will be passed.
  5. Write the modified presentation as a presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SimpleSlideTransitions.pptx";
const String outPath = u"../out/BetterSlideTransitions.pptx";
// Instantiate Presentation class
SharedPtr<Presentation>pres = MakeObject<Presentation>(templatePath);
// Apply circle type transition on slide 1
pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Circle);
// Set the transition time of 3 seconds
pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_AdvanceOnClick(true);
pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_AdvanceAfterTime(3000);
// Apply comb type transition on slide 2
pres->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Comb);
// Set the transition time of 5 seconds
pres->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_AdvanceOnClick(true);
pres->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_AdvanceAfterTime(5000);
// Write the presentation to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Morph Transition

Aspose.Slides for C++ now supports the Morph Transition. They represent new morph transition introduced in PowerPoint 2019. The Morph transition allows you to animate smooth movement from one slide to the next. This article describes the concept and how to use the Morph transition. To use the Morph transition effectively, you will need to have two slides with at least one object in common. The easiest way is to duplicate the slide and then move the object on the second slide to a different place.

The following code snippet shows you how to add a clone of the slide with some text to the presentation and set a transition of morph type to the second slide.

const String outPath = u"../out/presentation-out.pptx";
auto presentation = System::MakeObject<Presentation>();
auto autoshape = System::DynamicCast<Aspose::Slides::AutoShape>(presentation->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 100, 100, 400, 100));
autoshape->get_TextFrame()->set_Text(u"Test text");
presentation->get_Slides()->AddClone(presentation->get_Slides()->idx_get(0));
auto x = presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->get_X();
auto y = presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->get_Y();
auto width = presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->get_Width();
auto height = presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->get_Height();
presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->set_X(x + 100);
presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->set_Y(y + 50);
presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->set_Width(width + 200);
presentation->get_Slides()->idx_get(1)->get_Shapes()->idx_get(0)->set_Height(height + 10);
presentation->get_Slides()->idx_get(1)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Morph);
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Morph Transition Type

New Aspose.Slides.SlideShow.TransitionMorphType enum has been added. It represents different types of Morph slide transition.

TransitionMorphType enum has three members:

  • ByObject: Morph transition will be performed considering shapes as indivisible objects.
  • ByWord: Morph transition will be performed with transferring text by words where possible.
  • ByChar: Morph transition will be performed with transferring text by characters where possible.

The following code snippet shows you how to set morph transition to slide and change morph type:

const String inputPath = u"../templates/presentation.pptx";
const String outPath = u"../out/presentation-out.pptx";
auto presentation = System::MakeObject<Presentation>(u"presentation.pptx");
presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Morph);
auto morphTransition = System::DynamicCast<Aspose::Slides::SlideShow::IMorphTransition>(presentation->get_Slides()->idx_get(0)->get_SlideShowTransition()->get_Value());
morphTransition->set_MorphType(Aspose::Slides::SlideShow::TransitionMorphType::ByWord);
presentation->Save(u"presentation-out.pptx", Aspose::Slides::Export::SaveFormat::Pptx);

Set Transition Effects

Aspose.Slides for C++ supports setting the transition effects like, from black, from left, from right etc. In order to set the Transition Effect. Please follow the steps below:

  • Create an instance of Presentation class.
  • Get reference of the slide.
  • Setting the transition effect.
  • Write the presentation as a PPTX file.

In the example given below, we have set the transition effects.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SimpleSlideTransitions.pptx";
const String outPath = u"../out/TransitionEffects.pptx";
// Instantiate Presentation class
SharedPtr<Presentation>pres = MakeObject<Presentation>(templatePath);
// Apply circle type transition on slide 1
pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->set_Type(Aspose::Slides::SlideShow::TransitionType::Cut);
auto transition = DynamicCast<Aspose::Slides::SlideShow::OptionalBlackTransition>(pres->get_Slides()->idx_get(0)->get_SlideShowTransition()->get_Value());
transition->set_FromBlack(true);
// Write the presentation to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);