เพิ่มรูปร่างเส้นในงานนำเสนอบน Android
ภาพรวม
Aspose.Slides ให้คุณเพิ่มรูปร่างเส้นลงในสไลด์ PowerPoint อย่างอัตโนมัติ บทความนี้แสดงวิธีสร้างเส้นง่ายและวิธีปรับแต่งเส้นให้ปรากฏเป็นลูกศร
คุณจะได้เรียนรู้วิธีเพิ่มรูปร่างเส้นลงในสไลด์ ปรับลักษณะการแสดงผลของมัน และบันทึกงานนำเสนอที่อัปเดต ตัวอย่างจะเน้นการตั้งค่าการจัดรูปแบบเส้นที่ใช้งานได้จริง เช่น สไตล์ ความกว้าง แบบเส้นประ ตัวเลือกหัวศร และสีเติม
สร้างเส้นธรรมดา
เพื่อเพิ่มเส้นธรรมดาแบบง่ายลงในสไลด์ที่เลือกของงานนำเสนอ โปรดทำตามขั้นตอนด้านล่าง:
- สร้างอินสแตนซ์ของ Presentation class.
- รับอ้างอิงของสไลด์โดยใช้ Index ของมัน.
- เพิ่ม AutoShape ประเภท Line โดยใช้เมธอด addAutoShape ที่เปิดให้โดยอ็อบเจ็กต์ IShapeCollection.
- เขียนงานนำเสนอที่แก้ไขแล้วเป็นไฟล์ PPTX.
ในตัวอย่างที่ให้ไว้ด้านล่าง เราได้เพิ่มเส้นลงในสไลด์แรกของงานนำเสนอ
// สร้างอินสแตนซ์ของคลาส PresentationEx ที่แทนไฟล์ PPTX
Presentation pres = new Presentation();
try {
// ดึงสไลด์แรก
ISlide sld = pres.getSlides().get_Item(0);
// เพิ่ม AutoShape ชนิดเส้น
sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0);
// บันทึกไฟล์ PPTX ไปที่ดิสก์
pres.save("LineShape.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
สร้างเส้นรูปแบบลูกศร
Aspose.Slides for Android via Java ยังอนุญาตให้ผู้พัฒนากำหนดคุณสมบัติบางอย่างของเส้นเพื่อให้ดูน่าสนใจยิ่งขึ้น ลองกำหนดคุณสมบัติบางอย่างของเส้นเพื่อให้ดูเหมือนลูกศร ตามขั้นตอนด้านล่าง:
- สร้างอินสแตนซ์ของ Presentation class.
- รับอ้างอิงของสไลด์โดยใช้ Index ของมัน.
- เพิ่ม AutoShape ประเภท Line โดยใช้เมธอด addAutoShape ที่เปิดให้โดยอ็อบเจ็กต์ IShapeCollection.
- ตั้งค่า Line Style ให้เป็นหนึ่งในสไตล์ที่ Aspose.Slides for Android via Java มีให้.
- ตั้งค่าความกว้างของเส้น.
- ตั้งค่า Dash Style ของเส้นให้เป็นหนึ่งในสไตล์ที่ Aspose.Slides for Android via Java มีให้.
- ตั้งค่า Arrow Head Style และ Length ของจุดเริ่มต้นของเส้น.
- ตั้งค่า Arrow Head Style และ Length ของจุดสิ้นสุดของเส้น.
- เขียนงานนำเสนอที่แก้ไขแล้วเป็นไฟล์ PPTX.
// สร้างอินสแตนซ์ของคลาส PresentationEx ที่เป็นตัวแทนไฟล์ PPTX
Presentation pres = new Presentation();
try {
// ดึงสไลด์แรก
ISlide sld = pres.getSlides().get_Item(0);
// เพิ่ม AutoShape ชนิดเส้น
IAutoShape shp = sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0);
// กำหนดการจัดรูปแบบบางอย่างบนเส้น
shp.getLineFormat().setStyle(LineStyle.ThickBetweenThin);
shp.getLineFormat().setWidth(10);
shp.getLineFormat().setDashStyle(LineDashStyle.DashDot);
shp.getLineFormat().setBeginArrowheadLength(LineArrowheadLength.Short);
shp.getLineFormat().setBeginArrowheadStyle(LineArrowheadStyle.Oval);
shp.getLineFormat().setEndArrowheadLength(LineArrowheadLength.Long);
shp.getLineFormat().setEndArrowheadStyle(LineArrowheadStyle.Triangle);
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Maroon));
// บันทึกไฟล์ PPTX ลงดิสก์
pres.save("LineShape.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
คำถามที่พบบ่อย
ฉันสามารถแปลงเส้นปกติเป็นคอนเน็กเตอร์เพื่อให้มัน “ติด” กับรูปทรงได้ไหม?
No. A regular line (an AutoShape of type Line) does not automatically become a connector. To make it snap to shapes, use the dedicated Connector type and the corresponding APIs for connections.
ฉันควรทำอย่างไรหากคุณสมบัติของเส้นถูกสืบทอดมาจากธีมและยากที่จะกำหนดค่าที่สุดท้าย?
Read the effective properties through the ILineFormatEffectiveData/ILineFillFormatEffectiveData interfaces—these already account for inheritance and theme styles.
ฉันสามารถล็อกเส้นเพื่อป้องกันการแก้ไข (ย้าย, ปรับขนาด) ได้ไหม?
Yes. Shapes provide lock objects that let you disallow editing operations.