C++ を使用してプレゼンテーションにシェイプ アニメーションを適用
アニメーションは、テキスト、画像、図形、またはチャートに適用できる視覚効果です。プレゼンテーションやその構成要素に命を吹き込みます。
プレゼンテーションでアニメーションを使用する理由
- 情報の流れを制御する
- 重要なポイントを強調する
- 聴衆の関心や参加を高める
- コンテンツを読みやすく、理解しやすく、処理しやすくする
- 読者や視聴者の注意をプレゼンテーションの重要な部分へ引きつける
PowerPoint は、entrance、exit、emphasis、motion paths のカテゴリにまたがるアニメーションとアニメーション効果の多くのオプションとツールを提供します。
Aspose.Slides のアニメーション
- Aspose.Slides は、アニメーションを操作するために必要なクラスと型を Aspose.Slides.Animation 名前空間で提供します、
- Aspose.Slides は、EffectType 列挙型で 150 を超えるアニメーション効果を提供します。これらの効果は、基本的に PowerPoint で使用されるものと同じ(または同等)です。
テキストボックスへのアニメーション適用
Aspose.Slides for C++ を使用すると、図形内のテキストにアニメーションを適用できます。
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
rectangleの IAutoShape を追加します。- IAutoShape.TextFrame にテキストを追加します。
- 主要なエフェクトシーケンスを取得します。
- IAutoShape にアニメーション効果を追加します。
- TextAnimation.BuildType プロパティを BuildType Enumeration の値に設定します。
- プレゼンテーションを PPTX ファイルとしてディスクに書き込みます。
この C++ コードは、Fade 効果を AutoShape に適用し、テキストアニメーションを By 1st Level Paragraphs 値に設定する方法を示します:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを作成します。
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0);
// 新しい AutoShape をテキスト付きで追加
System::SharedPtr<IAutoShape> autoShape =
sld->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 20.0f, 20.0f, 150.0f, 100.0f);
System::SharedPtr<ITextFrame> textFrame = autoShape->get_TextFrame();
textFrame->set_Text(u"First paragraph \nSecond paragraph \n Third paragraph");
// スライドのメインシーケンスを取得
System::SharedPtr<ISequence> sequence = sld->get_Timeline()->get_MainSequence();
// シェイプに Fade アニメーション効果を追加
System::SharedPtr<IEffect> effect = sequence->AddEffect(autoShape, Aspose::Slides::Animation::EffectType::Fade,
Aspose::Slides::Animation::EffectSubtype::None, Aspose::Slides::Animation::EffectTriggerType::OnClick);
// シェイプのテキストを第1レベル段落単位でアニメーション
effect->get_TextAnimation()->set_BuildType(Aspose::Slides::Animation::BuildType::ByLevelParagraphs1);
// PPTX ファイルをディスクに保存
pres->Save(path + u"AnimText_out.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
PictureFrame へのアニメーション適用
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
- スライド上に PictureFrame を追加または取得します。
- 主要なエフェクトシーケンスを取得します。
- PictureFrame にアニメーション効果を追加します。
- プレゼンテーションを PPTX ファイルとしてディスクに書き込みます。
この C++ コードは、Fly 効果を picture frame に適用する方法を示します:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを生成します。
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
// プレゼンテーションの画像コレクションに追加する画像を読み込みます
System::SharedPtr<IImage> img = Images::FromFile(u"aspose-logo.jpg");
System::SharedPtr<IPPImage> image = pres->get_Images()->AddImage(img);
// スライドに画像フレームを追加します
System::SharedPtr<IPictureFrame> picFrame =
pres->get_Slides()->idx_get(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 50.0f, 50.0f, 100.0f, 100.0f, image);
// スライドのメインシーケンスを取得します
System::SharedPtr<ISequence> sequence = pres->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence();
// 画像フレームに左から飛び込むアニメーション効果を追加します
System::SharedPtr<IEffect> effect = sequence->AddEffect(picFrame, Aspose::Slides::Animation::EffectType::Fly,
Aspose::Slides::Animation::EffectSubtype::Left, Aspose::Slides::Animation::EffectTriggerType::OnClick);
// PPTX ファイルをディスクに保存します
pres->Save(path + u"AnimImage_out.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
Shape へのアニメーション適用
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
rectangleの IAutoShape を追加します。Bevelの IAutoShape を追加します(このオブジェクトをクリックすると、アニメーションが再生されます)。- Bevel 図形上でエフェクトシーケンスを作成します。
- カスタム
UserPathを作成します。 UserPathへ移動するコマンドを追加します。- プレゼンテーションを PPTX ファイルとしてディスクに書き込みます。
この C++ コードは、PathFootball(パスフットボール)効果を shape に適用する方法を示します:
// ドキュメントディレクトリへのパスです。
const String outPath = u"../out/AnimationsOnShapes_out.pptx";
const String templatePath = u"../templates/ConnectorLineAngle.pptx";
// プレゼンテーションをロードします
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// 最初のスライドにアクセスします
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// 選択したスライドのシェイプコレクションにアクセスします
SharedPtr<IShapeCollection> shapes = slide->get_Shapes();
// 既存シェイプ用に最初から PathFootball エフェクトを作成します。
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 150, 150, 250, 25);
ashp->AddTextFrame(u"Animated TextBox");
// PathFootBall アニメーション効果を追加します
slide->get_Timeline()->get_MainSequence()->AddEffect(ashp, EffectType::PathFootball,
EffectSubtype::None, EffectTriggerType::AfterPrevious);
// 何らかの「ボタン」を作成します。
SharedPtr<IAutoShape> shapeTrigger = slide->get_Shapes()->AddAutoShape(ShapeType::Bevel, 10, 10, 20, 20);
// このボタン用のエフェクトシーケンスを作成します。
SharedPtr<ISequence> seqInter = slide->get_Timeline()->get_InteractiveSequences()->Add(shapeTrigger);
// カスタムユーザーパスを作成します。ボタンがクリックされた後にのみオブジェクトが移動します。
SharedPtr<IEffect> fxUserPath = seqInter->AddEffect(ashp, EffectType::PathUser, EffectSubtype::None, EffectTriggerType::OnClick);
// 作成されたパスが空なので、移動コマンドを追加します。
SharedPtr<MotionEffect> motionBhv = ExplicitCast<MotionEffect>(fxUserPath->get_Behaviors()->idx_get(0));
// SharedPtr<PointF> point = MakeObject<PointF >(0.076, 0.59);
const PointF point = PointF (0.076, 0.59);
System::ArrayPtr<PointF> pts = System::MakeObject<System::Array<PointF>>(1, point);
motionBhv->get_Path()->Add(MotionCommandPathType::LineTo, pts, MotionPathPointsType::Auto, true);
//PointF point2[1] = { -0.076, -0.59 };
const PointF point2 = PointF(-0.076, -0.59 );
System::ArrayPtr<PointF> pts2 = System::MakeObject<System::Array<PointF>>(1, point2);
motionBhv->get_Path()->Add(MotionCommandPathType::LineTo, pts2, MotionPathPointsType::Auto, false);
motionBhv->get_Path()->Add(MotionCommandPathType::End, nullptr, MotionPathPointsType::Auto, false);
// PPTX ファイルをディスクに書き込みます
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
Shape に適用されたアニメーション効果の取得
以下の例は、ISequence インターフェイスの GetEffectsByShape メソッドを使用して、shape に適用されたすべてのアニメーション効果を取得する方法を示します。
例 1: 通常スライド上の shape に適用されたアニメーション効果の取得
以前、PowerPoint プレゼンテーションの shape にアニメーション効果を追加する方法を学びました。以下のサンプルコードは、プレゼンテーション AnimExample_out.pptx の最初の通常スライド上の最初の shape に適用された効果を取得する方法を示します。
SharedPtr<Presentation> presentation = MakeObject<Presentation>(u"AnimExample_out.pptx");
SharedPtr<ISlide> firstSlide = presentation->get_Slide(0);
// スライドのメインアニメーションシーケンスを取得します。
SharedPtr<ISequence> sequence = firstSlide->get_Timeline()->get_MainSequence();
// 最初のスライド上の最初のシェイプを取得します。
SharedPtr<IShape> shape = firstSlide->get_Shape(0);
// シェイプに適用されたアニメーション効果を取得します。
ArrayPtr<SharedPtr<IEffect>> shapeEffects = sequence->GetEffectsByShape(shape);
if (shapeEffects->get_Length() > 0)
{
Console::WriteLine(u"The shape " + shape->get_Name() + u" has " + shapeEffects->get_Length() + u" animation effects.");
}
presentation->Dispose();
例 2: プレースホルダーから継承されたものを含むすべてのアニメーション効果の取得
通常スライド上の shape がレイアウトスライドやマスタースライド上のプレースホルダーを持ち、これらのプレースホルダーにアニメーション効果が追加されている場合、スライドショー中に shape のすべての効果が再生され、プレースホルダーから継承された効果も含まれます。
たとえば、sample.pptx という PowerPoint プレゼンテーションファイルがあり、1 枚のスライドにフッター shape があり、テキストは「Made with Aspose.Slides」で、Random Bars 効果がその shape に適用されているとします。

また、layout スライドのフッタープレースホルダーに Split 効果が適用されているとします。

最後に、master スライドのフッタープレースホルダーに Fly In 効果が適用されているとします。

以下のサンプルコードは、IShape インターフェイスの GetBasePlaceholder メソッドを使用して shape のプレースホルダーにアクセスし、レイアウトおよびマスタースライド上のプレースホルダーから継承されたものを含むフッター shape に適用されたアニメーション効果を取得する方法を示します。
void PrintEffects(ArrayPtr<SharedPtr<IEffect>> effects)
{
for (SharedPtr<IEffect> effect : effects)
{
Console::WriteLine(String::Format(u"Type: {0}, subtype: {1}", effect->get_Type(), effect->get_Subtype()));
}
}
SharedPtr<Presentation> presentation = MakeObject<Presentation>(u"sample.pptx");
SharedPtr<ISlide> slide = presentation->get_Slide(0);
// 通常スライド上のシェイプのアニメーション効果を取得します。
SharedPtr<IShape> shape = slide->get_Shape(0);
ArrayPtr<SharedPtr<IEffect>> shapeEffects = slide->get_Timeline()->get_MainSequence()->GetEffectsByShape(shape);
// レイアウトスライド上のプレースホルダーのアニメーション効果を取得します。
SharedPtr<IShape> layoutShape = shape->GetBasePlaceholder();
ArrayPtr<SharedPtr<IEffect>> layoutShapeEffects = slide->get_LayoutSlide()->get_Timeline()->get_MainSequence()->GetEffectsByShape(layoutShape);
// マスタースライド上のプレースホルダーのアニメーション効果を取得します。
SharedPtr<IShape> masterShape = layoutShape->GetBasePlaceholder();
ArrayPtr<SharedPtr<IEffect>> masterShapeEffects = slide->get_LayoutSlide()->get_MasterSlide()->get_Timeline()->get_MainSequence()->GetEffectsByShape(masterShape);
presentation->Dispose();
Console::WriteLine(u"Main sequence of shape effects:");
PrintEffects(masterShapeEffects);
PrintEffects(layoutShapeEffects);
PrintEffects(shapeEffects);
Main sequence of shape effects:
Type: 47, subtype: 2 // Fly、ボトム
Type: 134, subtype: 45 // Split、VerticalIn
Type: 126, subtype: 22 // RandomBars、水平
アニメーション効果のタイミングプロパティの変更
Aspose.Slides for C++ を使用すると、アニメーション効果の Timing プロパティを変更できます。
これは Microsoft PowerPoint の Animation Timing ペインです:

これらは PowerPoint Timing と Effect.Timing プロパティ間の対応です:
- PowerPoint Timing の Start ドロップダウンリストは、Effect.Timing.TriggerType プロパティに対応します。
- PowerPoint Timing の Duration は、Effect.Timing.Duration プロパティに対応します。アニメーションの継続時間(秒)は、アニメーションが 1 サイクルを完了するまでの総時間です。
- PowerPoint Timing の Delay は、Effect.Timing.TriggerDelayTime プロパティに対応します。
Effect Timing プロパティを変更する手順は次のとおりです:
- Apply またはアニメーション効果を取得します。
- 必要な Effect.Timing プロパティに新しい値を設定します。
- 修正した PPTX ファイルを保存します。
この C++ コードは操作を示しています:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを作成します。
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"AnimExample_out.pptx");
// スライドのメインシーケンスを取得します。
System::SharedPtr<ISequence> sequence = pres->get_Slides()->idx_get(0)->get_Timeline()->get_MainSequence();
// メインシーケンスの最初のエフェクトを取得します。
System::SharedPtr<IEffect> effect = sequence->idx_get(0);
// エフェクトの TriggerType をクリックで開始するように変更します。
effect->get_Timing()->set_TriggerType(Aspose::Slides::Animation::EffectTriggerType::OnClick);
// エフェクトの Duration を変更します。
effect->get_Timing()->set_Duration(3.f);
// エフェクトの TriggerDelayTime を変更します。
effect->get_Timing()->set_TriggerDelayTime(0.5f);
// PPTX ファイルをディスクに保存します。
pres->Save(u"AnimExample_changed.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
アニメーション効果のサウンド
Aspose.Slides は、アニメーション効果のサウンドを操作するための以下のプロパティを提供します:
アニメーション効果サウンドの追加
この C++ コードは、アニメーション効果サウンドを追加し、次の効果が開始するときにそれを停止する方法を示します:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"AnimExample_out.pptx");
// プレゼンテーションのオーディオコレクションにオーディオを追加します
System::SharedPtr<IAudio> effectSound = pres->get_Audios()->AddAudio(System::IO::File::ReadAllBytes(u"sampleaudio.wav"));
System::SharedPtr<ISlide> firstSlide = pres->get_Slide(0);
// スライドのメインシーケンスを取得します。
System::SharedPtr<ISequence> sequence = firstSlide->get_Timeline()->get_MainSequence();
// メインシーケンスの最初のエフェクトを取得します
System::SharedPtr<IEffect> firstEffect = sequence->idx_get(0);
// エフェクトが「サウンドなし」かチェックします
if (!firstEffect->get_StopPreviousSound() && firstEffect->get_Sound() == nullptr)
{
// 最初のエフェクトにサウンドを追加します
firstEffect->set_Sound(effectSound);
}
// スライドの最初のインタラクティブシーケンスを取得します。
System::SharedPtr<ISequence> interactiveSequence = firstSlide->get_Timeline()->get_InteractiveSequence(0);
// エフェクトの「前のサウンドを止める」フラグを設定します
interactiveSequence->idx_get(0)->set_StopPreviousSound(true);
// PPTX ファイルをディスクに保存します
pres->Save(u"AnimExample_Sound_out.pptx", SaveFormat::Pptx);
アニメーション効果サウンドの抽出
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
- 主要なエフェクトシーケンスを取得します。
- 各アニメーション効果に埋め込まれた set_Sound() を抽出します。
この C++コードは、アニメーション効果に埋め込まれたサウンドを抽出する方法を示します:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを作成します。
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"EffectSound.pptx");
System::SharedPtr<ISlide> slide = pres->get_Slide(0);
// スライドのメインシーケンスを取得します。
System::SharedPtr<ISequence> sequence = slide->get_Timeline()->get_MainSequence();
for (auto&& effect : sequence)
{
System::SharedPtr<IAudio> sound = effect->get_Sound();
if (sound == nullptr)
continue;
auto audio = sound->get_BinaryData();
}
アフターアニメーション
Aspose.Slides for C++ を使用すると、アニメーション効果の After animation プロパティを変更できます。
これは Microsoft PowerPoint の Animation Effect ペインと拡張メニューです:

PowerPoint Effect の After animation ドロップダウンリストは、以下のプロパティに対応します:
- set_AfterAnimationType() プロパティは、After animation のタイプを示します:
- PowerPoint More Colors は、AfterAnimationType.Color タイプに対応します;
- PowerPoint Don’t Dim は、AfterAnimationType.DoNotDim タイプ(デフォルトの after animation タイプ)に対応します;
- PowerPoint Hide After Animation は、AfterAnimationType.HideAfterAnimation タイプに対応します;
- PowerPoint Hide on Next Mouse Click は、AfterAnimationType.HideOnNextMouseClick タイプに対応します;
- set_AfterAnimationColor() プロパティは、after animation のカラー形式を定義します。このプロパティは AfterAnimationType.Color タイプと連動します。タイプを別のものに変更すると、after animation のカラーはクリアされます。
この C++ コードは、after animation 効果を変更する方法を示します:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを作成します
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"AnimImage_out.pptx");
System::SharedPtr<ISlide> firstSlide = pres->get_Slide(0);
// メインシーケンスの最初のエフェクトを取得します
System::SharedPtr<IEffect> firstEffect = firstSlide->get_Timeline()->get_MainSequence()->idx_get(0);
// アフターアニメーションのタイプを Color に変更します
firstEffect->set_AfterAnimationType(AfterAnimationType::Color);
// アフターアニメーションの薄暗くなる色を設定します
firstEffect->get_AfterAnimationColor()->set_Color(System::Drawing::Color::get_AliceBlue());
// PPTX ファイルをディスクに書き込みます
pres->Save(u"AnimImage_AfterAnimation.pptx", SaveFormat::Pptx);
テキストのアニメーション
Aspose.Slides は、アニメーション効果の Animate text ブロックを操作するための以下のプロパティを提供します:
- set_AnimateTextType() は、効果のアニメートテキストタイプを示します。shape のテキストは次のようにアニメーション化できます:
- 一度に全体 (AnimateTextType.AllAtOnce タイプ)
- 単語ごとに (AnimateTextType.ByWord タイプ)
- 文字ごとに (AnimateTextType.ByLetter タイプ)
- set_DelayBetweenTextParts() は、アニメートされたテキスト部品(単語または文字)間の遅延を設定します。正の値は効果継続時間の割合を示し、負の値は秒単位の遅延を示します。
Effect Animate text プロパティを変更する手順は次のとおりです:
- Apply またはアニメーション効果を取得します。
- set_BuildType() プロパティを BuildType.AsOneObject の値に設定し、By Paragraphs アニメーションモードをオフにします。
- set_AnimateTextType() と set_DelayBetweenTextParts() プロパティに新しい値を設定します。
- 修正した PPTX ファイルを保存します。
この C++ コードは操作を示しています:
// プレゼンテーション ファイルを表すプレゼンテーションクラスのインスタンスを作成します。
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"AnimTextBox_out.pptx");
System::SharedPtr<ISlide> firstSlide = pres->get_Slide(0);
// メインシーケンスの最初のエフェクトを取得します
System::SharedPtr<IEffect> firstEffect = firstSlide->get_Timeline()->get_MainSequence()->idx_get(0);
// エフェクトのテキストアニメーションタイプを "As One Object" に変更します
firstEffect->get_TextAnimation()->set_BuildType(BuildType::AsOneObject);
// エフェクトのアニメートテキストタイプを "By word" に変更します
firstEffect->set_AnimateTextType(AnimateTextType::ByWord);
// エフェクトの継続時間の 20% に単語間の遅延を設定します
firstEffect->set_DelayBetweenTextParts(20.0f);
// PPTX ファイルをディスクに書き込みます
pres->Save(u"AnimTextBox_AnimateText.pptx", SaveFormat::Pptx);
FAQ
プレゼンテーションをウェブに公開する際にアニメーションを保持するにはどうすればよいですか?
Export to HTML5 を使用し、shape および transition アニメーションを有効にするオプションを有効にします。プレーン HTML ではスライドアニメーションは再生されませんが、HTML5 では再生されます。
shape の Z オーダー(レイヤー順序)を変更するとアニメーションにどのような影響がありますか?
アニメーションと描画順序は独立しています。エフェクトは表示/非表示のタイミングとタイプを制御し、z-order はどの要素が他の要素を覆うかを決定します。可視結果は両者の組み合わせで決まります。(これは一般的な PowerPoint の動作であり、Aspose.Slides のエフェクトと shape のモデルも同じロジックに従います。)
特定の効果をビデオに変換する際に制限はありますか?
一般に、アニメーションはサポートされています、ただしまれなケースや特定の効果は異なる方式でレンダリングされる可能性があります。使用する効果とライブラリのバージョンでテストすることを推奨します。