# 使用 C++ 为 PowerPoint 演示文稿添加动画

> 了解如何在 Aspose.Slides for C++ 中添加和控制高级动画效果，以创建动态的 PowerPoint 和 OpenDocument 演示文稿。

Source: https://docs.aspose.com/slides/zh/cpp/powerpoint-animation/
Updated: 2026-09-18

## **简介**

由于演示文稿旨在展示内容，在创建过程中始终会考虑其视觉外观和交互行为。

**PowerPoint 动画** 在使演示文稿引人注目并吸引观众方面发挥重要作用。Aspose.Slides 提供了多种向 PowerPoint 演示文稿添加动画的选项：

- 将各种 PowerPoint 动画效果应用于形状、图表、表格、OLE 对象和其他演示元素。
- 在单个形状上使用多个 PowerPoint 动画效果。
- 利用动画时间轴来控制动画效果。
- 创建自定义动画。

在 Aspose.Slides 中，可以对形状应用各种动画效果。由于幻灯片上的每个元素，包括文本、图片、OLE 对象和表格，都被视为形状，动画效果可以应用于幻灯片上的任何元素。

[Aspose::Slides::Animation](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/) 命名空间提供用于处理 PowerPoint 动画的类。

## **动画效果**
Aspose.Slides 支持 **150+ 动画效果**，包括诸如 Bounce、PathFootball 和 Zoom 等基本效果，以及 OLEObjectShow 和 OLEObjectOpen 等特定效果。完整列表可在 [EffectType](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/effecttype/) 枚举中找到。

此外，这些动画效果可以与以下行为组合使用：

- [ColorEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/coloreffect/)
- [CommandEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/commandeffect/)
- [FilterEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/filtereffect/)
- [MotionEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/motioneffect/)
- [PropertyEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/propertyeffect/)
- [RotationEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/rotationeffect/)
- [ScaleEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/scaleeffect/)
- [SetEffect](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/seteffect/)

## **自定义动画**
有关创建、检查和修改行为以及可编辑运动路径的完整 C++ 示例，请参阅 [Custom Animation](/slides/zh/cpp/custom-animation/)。

可以在 Aspose.Slides 中创建自己的 **自定义动画**。通过将多个行为组合成新的自定义动画即可实现此目的。

[Behavior](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/behavior/) 是 PowerPoint 动画效果的构建块。组合行为可自定义效果，或添加行为以扩展预定义效果。重复是通过时间设置配置的，而不是使用单独的重复行为。

[Animation Point](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/point/) 是应该应用行为的点。

## **动画时间轴**
[Sequence](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/sequence/) 是可针对不同形状的动画效果集合。

[IAnimationTimeLine](https://reference.aspose.com/slides/zh/cpp/aspose.slides/ianimationtimeline/) 是在特定幻灯片中使用的一组序列。它是 PowerPoint 2002 引入的动画引擎。在早期版本的 PowerPoint 中，向演示文稿添加动画效果具有挑战性，只能通过各种变通方法实现。时间轴为 PowerPoint 动画提供了更清晰的对象模型。每张幻灯片只能有一个动画时间轴。

## **交互式动画**
[Trigger](https://reference.aspose.com/slides/zh/cpp/aspose.slides.animation/effecttriggertype/) 允许您定义用户操作（例如按钮点击），以启动特定动画。

## **形状动画**
Aspose.Slides 允许您对形状应用动画，形状可以包括文本、矩形、线条、框架、OLE 对象等。

{{% alert color="info" title="Note" %}}
了解更多[**关于形状动画**](/slides/zh/cpp/shape-animation/)。
{{% /alert %}}

## **动画图表**
要创建动画图表，您应使用与形状相同的类。不过，PowerPoint 动画只能应用于图表类别或图表系列。您也可以将动画效果应用于类别元素或系列元素。

{{% alert color="info" title="Note" %}}
了解更多[**关于动画图表**](/slides/zh/cpp/animated-charts/)。
{{% /alert %}}

## **动画文本**
除了对文本进行动画，还可以对段落应用动画。

{{% alert color="info" title="Note" %}}
了解更多[**关于动画文本**](/slides/zh/cpp/animated-text/)。
{{% /alert %}}

## **常见问题**

**导出为 PDF 时动画会被保留吗？**

不。PDF 是静态格式，因此动画和 [slide transitions](/slides/zh/cpp/slide-transition/) 不会播放。如果需要动作，请导出为 [HTML5](/slides/zh/cpp/export-to-html5/)、[animated GIF](/slides/zh/cpp/convert-powerpoint-to-animated-gif/) 或 [video](/slides/zh/cpp/convert-powerpoint-to-video/) 。

**我可以将动画演示文稿转换为视频并控制帧率和帧大小吗？**

可以。您可以 [render the presentation as frames](/slides/zh/cpp/convert-powerpoint-to-video/) 并将其编码为视频（例如使用 ffmpeg），选择帧率和分辨率。在渲染过程中会播放动画和幻灯片切换效果。

**在使用 ODP（而不仅限于 PPTX）时动画会保持完整吗？**

PPT、PPTX 和 ODP 均受到 [reading](/slides/zh/cpp/open-presentation/) 和 [writing](/slides/zh/cpp/save-presentation/) 的支持，但这并不保证动画能够保留。转换为 ODP 时可能会丢失自定义动画数据。请参阅 [Custom Animation](/slides/zh/cpp/custom-animation/) 获取示例和检查格式兼容性的指南。
