สร้างและใช้เอฟเฟ็กต์ WordArt ใน .NET

ภาพรวม

เอฟเฟ็กต์ WordArt ช่วยให้คุณจัดรูปแบบข้อความด้วยการเติมสี, เส้นขอบ, เงา, การสะท้อน, แสงเรืองแสง, การแปลงรูป, และการจัดรูปแบบ 3 มิติ บทความนี้อธิบายวิธีสร้างและปรับแต่งเอฟเฟ็กต์เหล่านี้ในงานนำเสนอ PowerPoint ด้วย Aspose.Slides สำหรับ .NET โดยไม่ต้องติดตั้ง Microsoft Office.

สร้างเทมเพลต WordArt ง่ายและนำไปใช้กับข้อความ

ตัวอย่างต่อไปนี้สร้างสไตล์ WordArt แบบง่ายโดยกำหนดข้อความ, แบบอักษร, การเติมรูปแบบ, และเส้นขอบ.

แต่ละตัวอย่างสร้างการนำเสนอใหม่และเพิ่มสี่เหลี่ยมผืนผ้าลงในสไลด์แรก; ไม่ต้องการไฟล์อินพุต ตัวอย่างแรกกำหนดข้อความเป็น “Aspose.Slides” ตำแหน่งและขนาดของรูปทรงวัดเป็นหน่วยจุด:

using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);
var textFrame = autoShape.TextFrame;

var portion = textFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";

ตั้งแบบอักษรเป็น Arial Black ขนาด 36 จุดเพื่อให้การจัดรูปแบบชัดเจนขึ้น:

using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var portion = autoShape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";
portion.PortionFormat.LatinFont = new FontData("Arial Black");
portion.PortionFormat.FontHeight = 36;

ใช้รูปแบบ SmallGrid ที่มีสีพื้นหน้าสีส้มเข้มและพื้นหลังสีขาว จากนั้นเพิ่มเส้นขอบข้อความสีดำความกว้าง 1 จุด:

using System.Drawing;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var portion = autoShape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";
portion.PortionFormat.LatinFont = new FontData("Arial Black");
portion.PortionFormat.FontHeight = 36;

portion.PortionFormat.FillFormat.FillType = FillType.Pattern;
portion.PortionFormat.FillFormat.PatternFormat.ForeColor.Color = Color.DarkOrange;
portion.PortionFormat.FillFormat.PatternFormat.BackColor.Color = Color.White;
portion.PortionFormat.FillFormat.PatternFormat.PatternStyle = PatternStyle.SmallGrid;

portion.PortionFormat.LineFormat.Width = 1;
portion.PortionFormat.LineFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.LineFormat.FillFormat.SolidFillColor.Color = Color.Black;

ข้อความที่ได้: เทมเพลต WordArt ง่าย

ใช้เอฟเฟกต์ WordArt อื่นๆ

ตัวอย่างต่อไปนี้แสดงวิธีใช้เงา, การสะท้อน, แสงเรืองแสง, การแปลงรูป, และเอฟเฟ็กต์ 3 มิติบนข้อความ.

ใช้เอฟเฟกต์เงานอก

เงานอกเพิ่มความลึกโดยการวางเงาที่ด้านหลังข้อความ คุณสามารถปรับแต่งสี, ทิศทาง, ระยะทาง, รัศมีเบลอ, สเกล, และการเอียงได้.

ตัวอย่างนี้เรียกใช้ EnableOuterShadowEffect และกำหนดเงาสีดำที่มีรัศมีเบลอ 4 จุด, ทิศทาง 230 องศา, และระยะ 30 จุด ค่าสเกล 100 คงขนาดเงาไว้, ส่วนการเอียงแนวนอนทำให้เอียง 20 องศา การแปลงอัลฟ่าตั้งค่าความทึบเป็น 32%:

using System.Drawing;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var portion = autoShape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";
portion.PortionFormat.LatinFont = new FontData("Arial Black");
portion.PortionFormat.FontHeight = 36;

portion.PortionFormat.EffectFormat.EnableOuterShadowEffect();
portion.PortionFormat.EffectFormat.OuterShadowEffect.ShadowColor.Color = Color.Black;
portion.PortionFormat.EffectFormat.OuterShadowEffect.ScaleHorizontal = 100;
portion.PortionFormat.EffectFormat.OuterShadowEffect.ScaleVertical = 100;
portion.PortionFormat.EffectFormat.OuterShadowEffect.BlurRadius = 4;
portion.PortionFormat.EffectFormat.OuterShadowEffect.Direction = 230;
portion.PortionFormat.EffectFormat.OuterShadowEffect.Distance = 30;
portion.PortionFormat.EffectFormat.OuterShadowEffect.SkewHorizontal = 20;
portion.PortionFormat.EffectFormat.OuterShadowEffect.SkewVertical = 0;
portion.PortionFormat.EffectFormat.OuterShadowEffect.ShadowColor.ColorTransform.Add(ColorTransformOperation.SetAlpha, 0.32f);

ข้อความที่ได้: เอฟเฟกต์เงานอก

ใช้เอฟเฟ็กต์การสะท้อน

การสะท้อนสร้างสำเนาแบบกระจกของข้อความ ปรับตำแหน่ง, สเกล, เบลอ, และความทึบเพื่อตั้งค่าลักษณะการแสดง.

ตัวอย่างนี้เรียกใช้ EnableReflectionEffect และพลิกการสะท้อนในแนวตั้งด้วยสเกล -100% ใช้รัศมีเบลอ 0.5 จุดและระยะ 4.72 จุด ความทึบลดจาก 60% เหลือ 0.9% ระหว่างตำแหน่ง 0% ถึง 60% ตามการสะท้อน:

using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var portion = autoShape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";
portion.PortionFormat.LatinFont = new FontData("Arial Black");
portion.PortionFormat.FontHeight = 36;

portion.PortionFormat.EffectFormat.EnableReflectionEffect();
portion.PortionFormat.EffectFormat.ReflectionEffect.BlurRadius = 0.5;
portion.PortionFormat.EffectFormat.ReflectionEffect.Distance = 4.72;
portion.PortionFormat.EffectFormat.ReflectionEffect.StartPosAlpha = 0f;
portion.PortionFormat.EffectFormat.ReflectionEffect.EndPosAlpha = 60f;
portion.PortionFormat.EffectFormat.ReflectionEffect.Direction = 90;
portion.PortionFormat.EffectFormat.ReflectionEffect.ScaleHorizontal = 100;
portion.PortionFormat.EffectFormat.ReflectionEffect.ScaleVertical = -100;
portion.PortionFormat.EffectFormat.ReflectionEffect.StartReflectionOpacity = 60f;
portion.PortionFormat.EffectFormat.ReflectionEffect.EndReflectionOpacity = 0.9f;
portion.PortionFormat.EffectFormat.ReflectionEffect.RectangleAlign = RectangleAlignment.BottomLeft;

ข้อความที่ได้: เอฟเฟกต์การสะท้อน

สำหรับการเปรียบเทียบภาพตำแหน่งของกราเดียนต์, ค่าความทึบ, และมุมการจาง, ดูที่ ควบคุมการจางของการสะท้อน.

ใช้เอฟเฟกต์แสงเรืองแสง

แสงเรืองแสงเพิ่มเส้นขอบสีอ่อนรอบข้อความ ปรับสี, ความทึบ, และรัศมีเพื่อควบคุมเอฟเฟกต์.

ตัวอย่างนี้เรียกใช้ EnableGlowEffect และใช้แสงเรืองแสงสีแดงที่ความทึบ 54% และรัศมี 7 จุด:

using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var portion = autoShape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Aspose.Slides";
portion.PortionFormat.LatinFont = new FontData("Arial Black");
portion.PortionFormat.FontHeight = 36;

portion.PortionFormat.EffectFormat.EnableGlowEffect();
portion.PortionFormat.EffectFormat.GlowEffect.Color.Color = System.Drawing.Color.Red;
portion.PortionFormat.EffectFormat.GlowEffect.Color.ColorTransform.Add(ColorTransformOperation.SetAlpha, 0.54f);
portion.PortionFormat.EffectFormat.GlowEffect.Radius = 7;

ข้อความที่ได้: เอฟเฟกต์แสงเรืองแสง

ใช้การแปลง WordArt

การแปลง WordArt โค้ง, ยืด, หรือบิดบล็อกข้อความ.

ตั้งค่า Transform เป็น ArchUpPour เพื่อโค้งกรอบข้อความทั้งหมดขึ้นด้านบน:

using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);

var textFrame = autoShape.TextFrame;
textFrame.Text = "Aspose.Slides";
textFrame.TextFrameFormat.Transform = TextShapeType.ArchUpPour;

ข้อความที่ได้: การแปลง WordArt

ใช้เอฟเฟกต์ 3D กับรูปร่างและข้อความ

คุณสามารถใช้เอฟเฟกต์ 3D กับรูปร่างหรือกับข้อความของมันได้ เบเวล, การดันออก, แสงสว่าง, และการตั้งค่ากล้องควบคุมลักษณะที่ปรากฏ.

ตัวอย่างต่อไปนี้ใช้ ThreeDFormat เพื่อเพิ่มเบเวลวงกลม, การดันออกสีส้ม, และขอบสีแดงเข้มให้กับสี่เหลี่ยม มิติของเบเวล, ความสูงการดันออก, ความกว้างขอบ, และความลึกวัดเป็นจุด วัสดุพลาสติก, แสงสว่างสมดุลที่หมุน 40 องศารอบแกน Z, และกล้องมุมมองกำหนดลักษณะของมัน:

using System.Drawing;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);
autoShape.TextFrame.Text = "Aspose.Slides";

autoShape.ThreeDFormat.BevelBottom.BevelType = BevelPresetType.Circle;
autoShape.ThreeDFormat.BevelBottom.Height = 10.5;
autoShape.ThreeDFormat.BevelBottom.Width = 10.5;

autoShape.ThreeDFormat.BevelTop.BevelType = BevelPresetType.Circle;
autoShape.ThreeDFormat.BevelTop.Height = 12.5;
autoShape.ThreeDFormat.BevelTop.Width = 11;

autoShape.ThreeDFormat.ExtrusionColor.Color = Color.Orange;
autoShape.ThreeDFormat.ExtrusionHeight = 6;

autoShape.ThreeDFormat.ContourColor.Color = Color.DarkRed;
autoShape.ThreeDFormat.ContourWidth = 1.5;

autoShape.ThreeDFormat.Depth = 3;

autoShape.ThreeDFormat.Material = MaterialPresetType.Plastic;

autoShape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
autoShape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Balanced;
autoShape.ThreeDFormat.LightRig.SetRotation(0, 0, 40);

autoShape.ThreeDFormat.Camera.CameraType = CameraPresetType.PerspectiveContrastingRightFacing;

รูปร่างที่ได้: เอฟเฟกต์ 3D ของรูปร่าง

ตัวอย่างนี้ใช้การจัดรูปแบบ 3D คล้ายกันกับข้อความผ่าน TextFrameFormat.ThreeDFormat. เบเวลขนาดเล็กกว่าจะทำให้ขอบอักษรมีรูปทรง, ในขณะที่การดันออกและแสงสว่างให้ความลึกกับข้อความ:

using System.Drawing;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 200);
var textFrame = autoShape.TextFrame;
textFrame.Text = "Aspose.Slides";

textFrame.TextFrameFormat.ThreeDFormat.BevelBottom.BevelType = BevelPresetType.Circle;
textFrame.TextFrameFormat.ThreeDFormat.BevelBottom.Height = 3.5;
textFrame.TextFrameFormat.ThreeDFormat.BevelBottom.Width = 3.5;

textFrame.TextFrameFormat.ThreeDFormat.BevelTop.BevelType = BevelPresetType.Circle;
textFrame.TextFrameFormat.ThreeDFormat.BevelTop.Height = 4;
textFrame.TextFrameFormat.ThreeDFormat.BevelTop.Width = 4;

textFrame.TextFrameFormat.ThreeDFormat.ExtrusionColor.Color = Color.Orange;
textFrame.TextFrameFormat.ThreeDFormat.ExtrusionHeight = 6;

textFrame.TextFrameFormat.ThreeDFormat.ContourColor.Color = Color.DarkRed;
textFrame.TextFrameFormat.ThreeDFormat.ContourWidth = 1.5;

textFrame.TextFrameFormat.ThreeDFormat.Depth = 3;

textFrame.TextFrameFormat.ThreeDFormat.Material = MaterialPresetType.Plastic;

textFrame.TextFrameFormat.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
textFrame.TextFrameFormat.ThreeDFormat.LightRig.LightType = LightRigPresetType.Balanced;
textFrame.TextFrameFormat.ThreeDFormat.LightRig.SetRotation(0, 0, 40);

textFrame.TextFrameFormat.ThreeDFormat.Camera.CameraType = CameraPresetType.PerspectiveContrastingRightFacing;

ข้อความที่ได้: เอฟเฟกต์ 3D ของข้อความ

เพื่อให้ข้อความแบนและอ่านง่ายในขณะที่ยังคงการจัดรูปแบบ 3D ของรูปร่าง, ดูที่ ทำให้ข้อความแบนบนรูปร่าง 3D เพื่อเปรียบเทียบการตั้งค่าทั้งสองและตัวอย่าง C# เต็มรูปแบบ.

คำถามที่พบบ่อย

ฉันสามารถใช้เอฟเฟกต์ WordArt กับแบบอักษรหรือสคริปต์ที่ต่างกัน (เช่น อาหรับ, จีน) ได้หรือไม่?

ใช่, Aspose.Slides for .NET รองรับ Unicode และทำงานได้กับแบบอักษรและสคริปต์หลักทั้งหมด เอฟเฟกต์ WordArt เช่น เงา, การเติมสี, และเส้นขอบสามารถใช้ได้โดยไม่คำนึงถึงภาษ, แม้ว่าความพร้อมใช้งานของแบบอักษรและการเรนเดอร์อาจขึ้นอยู่กับแบบอักษรของระบบ.

ฉันสามารถใช้เอฟเฟกต์ WordArt กับองค์ประกอบมาสเตอร์สไลด์ได้หรือไม่?

ได้, คุณสามารถใช้เอฟเฟกต์ WordArt กับรูปทรงบนมาสเตอร์สไลด์ได้ รวมถึงตำแหน่งข้อความหัวเรื่อง, ส่วนท้าย, หรือข้อความพื้นหลัง การเปลี่ยนแปลงที่ทำในเค้าโครงมาสเตอร์จะสะท้อนไปยังสไลด์ที่เกี่ยวข้องทั้งหมด.

เอฟเฟกต์ WordArt มีผลต่อขนาดไฟล์งานนำเสนอหรือไม่?

เล็กน้อย. เอฟเฟกต์ WordArt เช่น เงา, แสงเรืองแสง, และการเติมสีไล่ระดับอาจทำให้ไฟล์ขนาดเพิ่มขึ้นเล็กน้อยเนื่องจากเมตาดาต้าการจัดรูปแบบเพิ่มเติม, แต่ส่วนต่างมักไม่สำคัญ.

ฉันสามารถดูตัวอย่างผลของเอฟเฟกต์ WordArt โดยไม่บันทึกงานนำเสนอได้หรือไม่?

ได้, คุณสามารถเรนเดอร์สไลด์ที่มี WordArt เป็นภาพ (เช่น PNG, JPEG) โดยใช้ ISlide.GetImage, หรือเรนเดอร์รูปร่างแต่ละรูปโดยใช้ IShape.GetImage. วิธีนี้ทำให้คุณสามารถดูตัวอย่างผลในหน่วยความจำหรือบนหน้าจอก่อนบันทึกหรือส่งออกงานนำเสนอเต็มรูปแบบ.