จัดการวัตถุ Ink ในการนำเสนอด้วย C++
บทนำ
PowerPoint มีฟีเจอร์ Ink ที่ให้คุณวาดเส้นอิสระได้ Ink สามารถใช้เพื่อไฮไลท์วัตถุอื่น ๆ แสดงการเชื่อมต่อและกระบวนการ และดึงความสนใจไปยังรายการเฉพาะบนสไลด์
The Aspose.Slides.Ink namespace contains the classes and interfaces needed to work with ink objects. For example, the IInk interface represents an ink object on a slide.
ความแตกต่างระหว่างวัตถุปกติและวัตถุ Ink
Objects on a PowerPoint slide are typically represented by shape objects. In its simplest form, a shape is a container that defines the area of the object itself (its frame) along with properties such as the container size, shape, and background. For more information, see Shape Layout Format.
อย่างไรก็ตามเมื่อ PowerPoint จัดการกับวัตถุ Ink มันจะละเลยคุณสมบัติทั้งหมดของกรอบวัตถุ (คอนเทนเนอร์) ยกเว้นขนาดของมัน ขนาดของพื้นที่คอนเทนเนอร์จะถูกกำหนดโดยเมธอดมาตรฐาน IShape::get_Width และ IShape::get_Height :

รอย Ink
An ink trace is a basic element used to record the trajectory of a pen as a user writes digital ink. A trace stores a sequence of connected points.
รูปแบบการเข้ารหัสที่ง่ายที่สุดระบุพิกัด X และ Y ของแต่ละจุดตัวอย่าง เมื่อจุดที่เชื่อมต่อทั้งหมดถูกเรนเดอร์ พวกมันจะสร้างภาพเช่นนี้:

คุณสมบัติของ Brush สำหรับการวาด
A brush is used to draw lines that connect the points of an ink trace. The brush has its own color and size, represented by the IInkBrush::get_Color and IInkBrush::get_Size methods.
ตั้งค่าสีของ Ink Brush
This C++ code shows how to set the color of an ink brush:
#include <DOM/Ink/IInk.h>
#include <DOM/Ink/IInkBrush.h>
#include <DOM/Ink/IInkTrace.h>
#include <DOM/Presentation.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
using Aspose::Slides::Ink::IInk;
using Aspose::Slides::Presentation;
using System::ExplicitCast;
using System::MakeObject;
auto presentation = MakeObject<Presentation>(u"pres.pptx");
auto ink = ExplicitCast<IInk>(presentation->get_Slide(0)->get_Shape(0));
auto inkTrace = ink->get_Traces()[0];
auto brush = inkTrace->get_Brush();
brush->set_Color(System::Drawing::Color::get_Red());
presentation->Dispose();
ตั้งค่าขนาดของ Ink Brush
This C++ code shows how to set the size of an ink brush:
#include <DOM/Ink/IInk.h>
#include <DOM/Ink/IInkBrush.h>
#include <DOM/Ink/IInkTrace.h>
#include <DOM/Presentation.h>
#include <drawing/size_f.h>
#include <system/smart_ptr.h>
using Aspose::Slides::Ink::IInk;
using Aspose::Slides::Presentation;
using System::ExplicitCast;
using System::MakeObject;
auto presentation = MakeObject<Presentation>(u"pres.pptx");
auto ink = ExplicitCast<IInk>(presentation->get_Slide(0)->get_Shape(0));
auto inkTrace = ink->get_Traces()[0];
auto brush = inkTrace->get_Brush();
brush->set_Size(System::Drawing::SizeF(5.0f, 10.0f));
presentation->Dispose();
โดยทั่วไป ความกว้างและความสูงของ brush จะไม่ตรงกัน ดังนั้น PowerPoint จึงไม่แสดงขนาดของ brush (ส่วนข้อมูลที่เกี่ยวข้องจะเป็นสีเทา) เมื่อความกว้างและความสูงของ brush ตรงกัน PowerPoint จะแสดงขนาดของมันดังนี้:

เพื่อความชัดเจน เราจะเพิ่มความสูงของวัตถุ Ink และพิจารณามิติที่สำคัญ:

คอนเทนเนอร์ (เฟรม) ไม่คำนึงถึงขนาดของ brush—มันจะถือว่าเส้นมีความหนาเป็นศูนย์เสมอ (ดูภาพก่อนหน้า)
ดังนั้นเพื่อกำหนดพื้นที่ที่มองเห็นของวัตถุ Ink ทั้งหมด ขนาดของ brush ในรอยต้องนำมาพิจารณา ที่นี่วัตถุเป้าหมาย (รอยข้อความที่เขียนด้วยมือ) ถูกสเกลให้ตรงกับขนาดของคอนเทนเนอร์ (เฟรม) เมื่อขนาดของคอนเทนเนอร์เปลี่ยนแปลง ขนาดของ brush จะคงที่ และในทางกลับกัน

PowerPoint ใช้พฤติกรรมคล้ายกันสำหรับวัตถุข้อความ:

ควบคุมลักษณะของ Ink ระหว่างการส่งออกและการเรนเดอร์
Aspose.Slides provides the IInkOptions interface to control how ink objects appear in exported or rendered output. You can use its methods to hide ink completely or change how ink brush mask operations are interpreted.
Ink options are available through the export or rendering options for several output types:
| ผลลัพธ์ | วิธีการ Ink options |
|---|---|
| PdfOptions::get_InkOptions | |
| HTML | HtmlOptions::get_InkOptions |
| SVG | SVGOptions::get_InkOptions |
| TIFF | TiffOptions::get_InkOptions |
| Slide image | RenderingOptions::get_InkOptions |
The same two settings are available through these methods:
- IInkOptions::set_HideInk determines whether ink objects are included in the output. Its default value is
false. - IInkOptions::set_InterpretMaskOpAsOpacity determines whether a mask operation is interpreted as opacity when rendering an ink brush. Its default value is
true; set it tofalseto use the ROP operation instead.
ซ่อนวัตถุ Ink ในผลลัพธ์ PDF
By default, ink objects remain visible during export. Call IInkOptions::set_HideInk with true when you need a clean output without handwritten annotations or other ink content.
The following C++ example exports a presentation to PDF while hiding all ink objects:
#include <DOM/Presentation.h>
#include <Export/IInkOptions.h>
#include <Export/PdfOptions.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
using Aspose::Slides::Presentation;
using Aspose::Slides::Export::PdfOptions;
using Aspose::Slides::Export::SaveFormat;
using System::MakeObject;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto pdfOptions = MakeObject<PdfOptions>();
pdfOptions->get_InkOptions()->set_HideInk(true);
presentation->Save(u"presentation_without_ink.pdf", SaveFormat::Pdf, pdfOptions);
presentation->Dispose();
ซ่อนวัตถุ Ink เมื่อเรนเดอร์สไลด์เป็นภาพ
To hide ink objects when rendering slides as bitmap images, configure RenderingOptions::get_InkOptions and pass the rendering options to the ISlide::GetImage method.
The following C++ example renders the first slide as a PNG image without ink objects:
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/IInkOptions.h>
#include <Export/RenderingOptions.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <system/smart_ptr.h>
using Aspose::Slides::ImageFormat;
using Aspose::Slides::Presentation;
using Aspose::Slides::Export::RenderingOptions;
using System::MakeObject;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto renderingOptions = MakeObject<RenderingOptions>();
renderingOptions->get_InkOptions()->set_HideInk(true);
auto image = presentation->get_Slide(0)->GetImage(renderingOptions);
image->Save(u"slide_without_ink.png", ImageFormat::Png);
image->Dispose();
presentation->Dispose();
ควบคุมการเรนเดอร์ Mask ของ Ink
The IInkOptions::set_InterpretMaskOpAsOpacity method controls how mask operations are interpreted when rendering ink brushes. The default value is true, which uses opacity. Call the method with false to use the ROP operation instead.
The following C++ example exports a slide to SVG and uses ROP-based rendering for ink mask operations:
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/IInkOptions.h>
#include <Export/SVGOptions.h>
#include <system/io/file.h>
#include <system/smart_ptr.h>
using Aspose::Slides::Presentation;
using Aspose::Slides::Export::SVGOptions;
using System::MakeObject;
using System::IO::File;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto svgOptions = MakeObject<SVGOptions>();
svgOptions->get_InkOptions()->set_InterpretMaskOpAsOpacity(false);
auto stream = File::Create(u"slide.svg");
presentation->get_Slide(0)->WriteAsSvg(stream, svgOptions);
stream->Dispose();
presentation->Dispose();
The same setting can be applied through TiffOptions::get_InkOptions when exporting a presentation or rendering a slide to TIFF.
เลือกว่าจะซ่อนหรือรักษา Ink
Use IInkOptions::set_HideInk with true when the exported file should be a clean version of an annotated presentation, for example, a final copy intended for distribution without review marks.
Leave ink visible (the default false setting) when ink annotations are part of the intended content, such as review comments, handwritten notes, highlights, or drawings that should remain visible in the exported result. This allows applications to generate separate review and final outputs from the same presentation without modifying the source ink objects.
คำถามที่พบบ่อย
ฉันสามารถเปลี่ยนสีหรือขนาดของเส้น Ink ที่มีอยู่ได้หรือไม่?
Yes. Get the trace from IInk::get_Traces, then change its IInkTrace::get_Brush. You can call IInkBrush::set_Color and IInkBrush::set_Size on the brush.
การซ่อน Ink จะเปลี่ยนแปลงการนำเสนอที่เป็นต้นทางหรือไม่?
No. IInkOptions::set_HideInk affects only the rendered or exported result; it does not remove or modify ink objects in the source presentation.
ฟอร์แมตการส่งออกใดบ้างที่รองรับ Ink options?
You can configure ink options for PDF, HTML, SVG, TIFF, and bitmap slide images through the corresponding export or rendering options shown above.
อ่านเพิ่มเติม
- To read about shapes in general, see the PowerPoint Shapes section.
- For more information on effective values, see Shape Effective Properties.
- For details on PDF export, see Convert PPT and PPTX to PDF.
- For details on HTML export, see Convert PowerPoint Presentations to HTML.
- For details on SVG export, see Render Presentation Slides as SVG Images.
- For details on TIFF export, see Convert PowerPoint Presentations to TIFF.
- For details on slide-to-image rendering, see Convert Presentation Slides to Images.