ใช้แอนิเมชันรูปร่างในงานนำเสนอด้วย C++
บทนำ
แอนิเมชันคือเอฟเฟกต์ภาพที่สามารถใช้กับข้อความ, รูปภาพ, รูปร่าง, หรือ แผนภูมิ. พวกมันให้ชีวิตแก่การนำเสนอหรือส่วนประกอบของมัน.
ทำไมต้องใช้แอนิเมชันในงานนำเสนอ?
ใช้แอนิเมชันคุณสามารถ
- ควบคุมการไหลของข้อมูล
- เน้นจุดสำคัญ
- เพิ่มความสนใจหรือการมีส่วนร่วมของผู้ฟัง
- ทำให้เนื้อหาอ่านง่ายหรือทำความเข้าใจหรือประมวลผลได้ง่ายขึ้น
- ดึงดูดความสนใจของผู้อ่านหรือผู้ชมไปยังส่วนสำคัญในการนำเสนอ
PowerPoint มีตัวเลือกและเครื่องมือหลากหลายสำหรับแอนิเมชันและเอฟเฟกต์แอนิเมชันในหมวด entrance, exit, emphasis, และ motion paths.
แอนิเมชันใน Aspose.Slides
- Aspose.Slides มีคลาสและประเภทที่คุณต้องการเพื่อทำงานกับแอนิเมชันภายใต้เนมสเปซ Aspose.Slides.Animation.
- Aspose.Slides มีเอฟเฟกต์แอนิเมชันกว่า 150 รายการภายใต้การระบุ EffectType. เอฟเฟกต์เหล่านี้โดยพื้นฐานแล้วเหมือนกับ (หรือเทียบเท่า) เอฟเฟกต์ที่ใช้ใน PowerPoint.
ใช้แอนิเมชันกับ TextBox
Aspose.Slides สำหรับ C++ ช่วยให้คุณสามารถใช้แอนิเมชันกับข้อความในรูปร่างได้.
- สร้างอินสแตนซ์ของคลาส Presentation.
- รับอ้างอิงสไลด์ผ่านดัชนีของมัน.
- เพิ่ม
rectangleIAutoShape. - เพิ่มข้อความไปยัง IAutoShape.TextFrame.
- รับลำดับหลักของเอฟเฟกต์.
- เพิ่มเอฟเฟกต์แอนิเมชันให้กับ IAutoShape.
- ตั้งค่าคุณสมบัติ TextAnimation.BuildType ให้เป็นค่าจาก BuildType Enumeration.
- บันทึกการนำเสนอลงดิสก์เป็นไฟล์ PPTX.
โค้ด C++ นี้แสดงวิธีการใช้เอฟเฟกต์ Fade กับ AutoShape และตั้งค่าแอนิเมชันของข้อความเป็นค่าที่ By 1st Level Paragraphs :
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ.
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0);
// Adds new AutoShape with text
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");
// Gets the main sequence of the slide.
System::SharedPtr<ISequence> sequence = sld->get_Timeline()->get_MainSequence();
// Adds Fade animation effect to shape
System::SharedPtr<IEffect> effect = sequence->AddEffect(autoShape, Aspose::Slides::Animation::EffectType::Fade,
Aspose::Slides::Animation::EffectSubtype::None, Aspose::Slides::Animation::EffectTriggerType::OnClick);
// Animates shape text by 1st level paragraphs
effect->get_TextAnimation()->set_BuildType(Aspose::Slides::Animation::BuildType::ByLevelParagraphs1);
// Save the PPTX file to disk
pres->Save(path + u"AnimText_out.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
ใช้แอนิเมชันกับ PictureFrame
- สร้างอินสแตนซ์ของคลาส Presentation.
- รับอ้างอิงสไลด์ผ่านดัชนีของมัน.
- เพิ่มหรือรับ PictureFrame บนสไลด์.
- รับลำดับหลักของเอฟเฟกต์.
- เพิ่มเอฟเฟกต์แอนิเมชันให้กับ PictureFrame.
- บันทึกการนำเสนอลงดิสก์เป็นไฟล์ PPTX.
โค้ด C++ นี้แสดงวิธีการใช้เอฟเฟกต์ Fly กับ picture frame:
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ.
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);
// เพิ่ม picture frame ไปยังสไลด์
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();
// เพิ่มเอฟเฟกต์แอนิเมชัน Fly จากด้านซ้ายให้กับ picture frame
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.
- รับอ้างอิงสไลด์ผ่านดัชนีของมัน.
- เพิ่ม
rectangleIAutoShape. - เพิ่ม
BevelIAutoShape (เมื่อออบเจ็กต์นี้ถูกคลิก แอนิเมชันจะเล่น). - สร้างลำดับของเอฟเฟกต์บนรูปร่าง bevel.
- สร้าง
UserPathที่กำหนดเอง. - เพิ่มคำสั่งสำหรับการย้ายไปยัง
UserPath. - บันทึกการนำเสนอลงดิสก์เป็นไฟล์ PPTX.
โค้ด C++ นี้แสดงวิธีการใช้เอฟเฟกต์ PathFootball (path football) กับ 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
ตัวอย่างต่อไปนี้แสดงวิธีการใช้เมธอด GetEffectsByShape จากอินเทอร์เฟซ ISequence เพื่อรับเอฟเฟกต์แอนิเมชันทั้งหมดที่ใช้กับรูปร่าง.
ตัวอย่างที่ 1: รับเอฟเฟกต์แอนิเมชันที่ใช้กับรูปร่างบนสไลด์ปกติ
ก่อนหน้านี้คุณได้เรียนรู้วิธีเพิ่มเอฟเฟกต์แอนิเมชันให้กับรูปร่างในงานนำเสนอ PowerPoint. ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการรับเอฟเฟกต์ที่ใช้กับรูปร่างแรกบนสไลด์ปกติแรกในงานนำเสนอ AnimExample_out.pptx.
SharedPtr<Presentation> presentation = MakeObject<Presentation>(u"AnimExample_out.pptx");
SharedPtr<ISlide> firstSlide = presentation->get_Slide(0);
// Gets the main animation sequence of the slide.
SharedPtr<ISequence> sequence = firstSlide->get_Timeline()->get_MainSequence();
// Gets the first shape on the first slide.
SharedPtr<IShape> shape = firstSlide->get_Shape(0);
// Gets animation effects applied to the shape.
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: รับเอฟเฟกต์แอนิเมชันทั้งหมด รวมถึงที่สืบทอดจาก placeholder
หากรูปร่างบนสไลด์ปกติมี placeholder ที่อยู่บนสไลด์ layout และ/หรือ master, และมีการเพิ่มเอฟเฟกต์แอนิเมชันให้กับ placeholder เหล่านั้น, เอฟเฟกต์ทั้งหมดของรูปร่างจะถูกเล่นระหว่างการแสดงสไลด์, รวมถึงที่สืบทอดจาก placeholder.
สมมติว่าเรามีไฟล์ PowerPoint sample.pptx ที่มีสไลด์หนึ่งสไลด์ซึ่งมีเพียงรูปร่าง footer ที่มีข้อความ “Made with Aspose.Slides” และมีการใช้เอฟเฟกต์ Random Bars กับรูปร่างนั้น.

สมมติเพิ่มเติมว่าเอฟเฟกต์ Split ถูกใช้กับ placeholder ของ footer บนสไลด์ layout.

และสุดท้ายเอฟเฟกต์ Fly In ถูกใช้กับ placeholder ของ footer บนสไลด์ master.

โค้ดตัวอย่างต่อไปนี้แสดงวิธีการใช้เมธอด GetBasePlaceholder จากอินเทอร์เฟซ IShape เพื่อเข้าถึง placeholder ของรูปร่างและรับเอฟเฟกต์แอนิเมชันที่ใช้กับรูปร่าง footer, รวมถึงที่สืบทอดจาก placeholder ที่อยู่บนสไลด์ layout และ master.
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);
// รับเอฟเฟกต์แอนิเมชันของ placeholder บนสไลด์ layout.
SharedPtr<IShape> layoutShape = shape->GetBasePlaceholder();
ArrayPtr<SharedPtr<IEffect>> layoutShapeEffects = slide->get_LayoutSlide()->get_Timeline()->get_MainSequence()->GetEffectsByShape(layoutShape);
// รับเอฟเฟกต์แอนิเมชันของ placeholder บนสไลด์ master.
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);
Output:
Main sequence of shape effects:
Type: 47, subtype: 2 // บิน, ด้านล่าง
Type: 134, subtype: 45 // แยก, เข้าตั้งแนวตั้ง
Type: 126, subtype: 22 // แถบสุ่ม, แนวนอน
เปลี่ยนคุณสมบัติ Timing ของเอฟเฟกต์แอนิเมชัน
Aspose.Slides สำหรับ C++ ช่วยให้คุณเปลี่ยนคุณสมบัติ Timing ของเอฟเฟกต์แอนิเมชันได้.
นี่คือแผง Animation Timing ใน Microsoft PowerPoint:

ความสัมพันธ์ระหว่าง PowerPoint Timing กับคุณสมบัติ Effect.Timing มีดังนี้:
- รายการดรอปดาวน์ Start ของ PowerPoint ตรงกับคุณสมบัติ Effect.Timing.TriggerType.
- รายการ Duration ของ PowerPoint ตรงกับคุณสมบัติ Effect.Timing.Duration. ระยะเวลาของแอนิเมชัน (วินาที) คือเวลาทั้งหมดที่แอนิเมชันใช้ในการทำรอบหนึ่ง.
- รายการ Delay ของ PowerPoint ตรงกับคุณสมบัติ Effect.Timing.TriggerDelayTime.
วิธีการเปลี่ยนคุณสมบัติ Timing ของเอฟเฟกต์:
- Apply หรือรับเอฟเฟกต์แอนิเมชัน.
- ตั้งค่าคุณสมบัติ Effect.Timing ที่ต้องการใหม่.
- บันทึกไฟล์ PPTX ที่แก้ไขแล้ว.
โค้ด C++ นี้แสดงการดำเนินการ:
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ.
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++ นี้แสดงวิธีการดึงเสียงที่ฝังอยู่ในเอฟเฟกต์แอนิเมชัน:
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ.
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();
}
After Animation
Aspose.Slides สำหรับ C++ ช่วยให้คุณเปลี่ยนคุณสมบัติ After animation ของเอฟเฟกต์แอนิเมชันได้.
นี่คือแผง After Animation ใน Microsoft PowerPoint:

รายการดรอปดาวน์ After animation ของ PowerPoint ตรงกับคุณสมบัติดังนี้:
- คุณสมบัติ set_AfterAnimationType() ซึ่งกำหนดประเภท After animation :
- รายการ More Colors ของ PowerPoint ตรงกับประเภท AfterAnimationType.Color.
- รายการ Don’t Dim ของ PowerPoint ตรงกับประเภท AfterAnimationType.DoNotDim (ค่าเริ่มต้นของ After animation).
- รายการ Hide After Animation ของ PowerPoint ตรงกับประเภท AfterAnimationType.HideAfterAnimation.
- รายการ Hide on Next Mouse Click ของ PowerPoint ตรงกับประเภท AfterAnimationType.HideOnNextMouseClick.
- คุณสมบัติ set_AfterAnimationColor() ซึ่งกำหนดรูปแบบสีของ After animation. คุณสมบัตินี้ทำงานร่วมกับประเภท AfterAnimationType.Color. หากคุณเปลี่ยนประเภทเป็นค่าอื่น สีของ After animation จะถูกล้าง.
โค้ด C++ นี้แสดงวิธีการเปลี่ยนเอฟเฟกต์ After animation:
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ
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);
// เปลี่ยนประเภท After animation เป็น Color
firstEffect->set_AfterAnimationType(AfterAnimationType::Color);
// ตั้งค่าสีของ After animation dim
firstEffect->get_AfterAnimationColor()->set_Color(System::Drawing::Color::get_AliceBlue());
// บันทึกไฟล์ PPTX ลงดิสก์
pres->Save(u"AnimImage_AfterAnimation.pptx", SaveFormat::Pptx);
Animate Text
Aspose.Slides มีคุณสมบัติเหล่านี้เพื่อให้คุณทำงานกับบล็อก Animate text ของเอฟเฟกต์แอนิเมชัน:
- set_AnimateTextType() ซึ่งกำหนดประเภทการแอนิเมตข้อความของเอฟเฟกต์. ข้อความของรูปร่างสามารถแอนิเมตได้:
- ทั้งหมดพร้อมกัน (AnimateTextType.AllAtOnce type)
- ตามคำ (AnimateTextType.ByWord type)
- ตามตัวอักษร (AnimateTextType.ByLetter type)
- set_DelayBetweenTextParts() ตั้งค่าความล่าช้าระหว่างส่วนของข้อความที่แอนิเมต (คำหรืออักษร). ค่าเป็นบวกระบุเปอร์เซ็นต์ของระยะเวลาเอฟเฟกต์. ค่าเป็นลบระบุความล่าช้าเป็นวินาที.
นี่คือวิธีการเปลี่ยนคุณสมบัติ Animate text ของเอฟเฟกต์:
- Apply หรือรับเอฟเฟกต์แอนิเมชัน.
- ตั้งค่าคุณสมบัติ set_BuildType() ให้เป็นค่า BuildType.AsOneObject เพื่อปิดโหมดแอนิเมชัน By Paragraphs.
- ตั้งค่าคุณสมบัติ set_AnimateTextType() และ set_DelayBetweenTextParts() ใหม่ตามต้องการ.
- บันทึกไฟล์ PPTX ที่แก้ไขแล้ว.
โค้ด C++ นี้แสดงการดำเนินการ:
// สร้างอินสแตนซ์ของคลาส Presentation ที่เป็นตัวแทนของไฟล์การนำเสนอ.
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 และเปิดใช้งาน options ที่รับผิดชอบต่อการแอนิเมชันของ shape และ transition. HTML ปกติไม่เล่นแอนิเมชันสไลด์, ส่วน HTML5 เล่นได้.
การเปลี่ยนลำดับ z-order (ลำดับชั้น) ของรูปร่างส่งผลต่อแอนิเมชันอย่างไร?
แอนิเมชันและลำดับการวาดเป็นสิ่งอิสระ: เอฟเฟกต์กำหนดเวลาและประเภทการปรากฏ/หายไป, ในขณะที่ z-order กำหนดว่าอะไรอยู่เหนืออะไร. ผลลัพธ์ที่มองเห็นได้กำหนดโดยการผสมผสานของทั้งสอง (นี่คือพฤติกรรมทั่วไปของ PowerPoint; โมเดลเอฟเฟกต์และรูปร่างของ Aspose.Slides ยึดตามหลักการเดียวกัน).
มีข้อจำกัดใดเมื่อแปลงแอนิเมชันเป็นวิดีโอสำหรับเอฟเฟกต์บางอย่างหรือไม่?
โดยทั่วไป animations are supported, แต่ในบางกรณีหรือเอฟเฟกต์เฉพาะอาจแสดงผลต่างออกไป. แนะนำให้ทดสอบกับเอฟเฟกต์ที่คุณใช้และเวอร์ชันของไลบรารี.