添加图片框架并应用动画 使用 VSTO 和 Aspose.Slides for .NET

添加图片框架并应用动画

下面的代码示例创建一个包含幻灯片的演示文稿,向其中添加带有图片框架的图像并对其应用动画。

VSTO 2008 示例

使用 VSTO 2008,请执行以下步骤:

  1. 创建演示文稿。
  2. 添加一个空白幻灯片。
  3. 向幻灯片添加图片形状。
  4. 对图片应用动画。
  5. 将演示文稿写入磁盘。

使用 VSTO 创建的输出演示文稿

todo:image_alt_text

//创建空白演示文稿
PowerPoint.Presentation pres = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

//Add a blank slide
PowerPoint.Slide sld = pres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);

//Add Picture Frame
PowerPoint.Shape PicFrame = sld.Shapes.AddPicture(@"D:\Aspose Data\Desert.jpg",
Microsoft.Office.Core.MsoTriState.msoTriStateMixed,
Microsoft.Office.Core.MsoTriState.msoTriStateMixed, 150, 100, 400, 300);

//Applying animation on picture frame
PicFrame.AnimationSettings.EntryEffect = Microsoft.Office.Interop.PowerPoint.PpEntryEffect.ppEffectBoxIn;

//Saving Presentation
pres.SaveAs("d:\\ VSTOAnim.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
Microsoft.Office.Core.MsoTriState.msoFalse);

Aspose.Slides for .NET 示例

使用 Aspose.Slides for .NET,执行以下步骤:

  1. 创建演示文稿。
  2. 访问第一张幻灯片。
  3. 将图像添加到图片集合中。
  4. 向幻灯片添加图片形状。
  5. 对图片应用动画。
  6. 将演示文稿写入磁盘。

使用 Aspose.Slides 创建的输出演示文稿

todo:image_alt_text

// 创建空白演示文稿
using (Presentation pres = new Presentation())
{
    // 访问第一张幻灯片
    ISlide slide = pres.Slides[0];

    // 将图像添加到演示文稿的图像集合中
    IImage image = Images.FromFile("aspose.jpg");
    IPPImage ppImage = pres.Images.AddImage(image);
    image.Dispose();

    // 添加一个宽高与图像相同的图片框架
    IPictureFrame pictureFrame = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 150, ppImage.Width, ppImage.Height, ppImage);

    // 获取幻灯片的主动画序列
    ISequence sequence = pres.Slides[0].Timeline.MainSequence;

    // 为图片框架添加从左侧飞入的动画效果
    IEffect effect = sequence.AddEffect(pictureFrame, EffectType.Fly, EffectSubtype.Left, EffectTriggerType.OnClick);

    // 保存演示文稿
    pres.Save("AsposeAnim.ppt", SaveFormat.Ppt);
}