How to Add Reflection Effect to Text in C
使用 IronWord 簡單的 API,在 C# 中對文字套用鏡子般的反射效果。 只需一行程式碼即可建立專業的文字反射效果,模擬文字反射在表面上,增強視覺深度。
快速入門:在 C# 中對文字套用反射效果
使用 IronWord,只需一行程式碼,即可將預設的反射效果套用至任何文字。 立即開始使用 - 不需要複雜的設定或模板程式碼。
-
使用NuGet套件管理器安裝https://www.nuget.org/packages/IronWord
PM > Install-Package IronWord -
複製並運行這段程式碼。
using IronWord; using IronWord.Models; WordDocument doc = new WordDocument(); TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { ReflectionEffect = new Reflection() }; Paragraph paragraph = new Paragraph(); Run textRun = new Run(new TextContent("Reflection Text")); textRun.Style = textStyle; paragraph.AddChild(textRun); doc.AddParagraph(paragraph); doc.SaveAs("reflection.docx"); -
部署到您的生產環境進行測試
今天就在您的專案中開始使用免費試用IronWord
如何為文字添加反射效果(5 個步驟)
- 安裝 IronWord:`Install-Package IronWord`
- 建立 `TextStyle` 並使用 `new Reflection()` 來設定 `ReflectionEffect`
- 建立一個包含 `TextContent` 的 `Run`,並將 `TextStyle` 指派給該 `Run`
- 使用 `AddChild` 將 `Run` 加入段落
- 儲存文件
如何新增反射效果?
To apply a reflection effect, create a TextStyle and populate its TextEffect property with a ReflectionEffect. Then create a Paragraph, followed by a Run containing TextContent. Assign the TextStyle to the Run (not the TextContent), then use AddChild to add the Run to the Paragraph. 此文件遵循以下層級結構:文件 → 段落 → 執行 → 文字內容。
反射效果可為重要的文字元素增加深度和視覺趣味,從而增強文件的呈現效果。 這種效果特別適用於標題、標題以及強調專業文件中的關鍵資訊。 倒影模擬文字坐在光滑的表面上,創造出優雅、現代的外觀,吸引讀者的注意力。
為何建立 TextStyle 如此重要?
TextStyle 物件是 IronWord 中所有文字格式設定的核心配置點。 透過將樣式與內容分離,您可以在多個文字元素中重複使用相同的反射效果,確保整個文件的一致性。 這種方法也可以輕鬆地透過修改單一樣式物件來全局更新反射效果。
:path=/static-assets/word/content-code-examples/how-to/text-effect-reflection-effect.cs
using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection(),
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("reflectionEffect.docx");
Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection()
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("reflectionEffect.docx")
預設的反射是什麼樣子?
預設的反射效果會在文字下方建立微妙的鏡像,並自動淡化不透明度。 此預設組態適用於大多數的商業文件和簡報,不需要任何額外的客製化。 映像會以標準距離出現,並搭配適當的模糊與透明度設定,以補足各種字型大小與樣式。
我可以為反射效果設定哪些屬性?
反射效果提供了一系列可調節的屬性,以滿足不同的設計需求。 瞭解這些屬性後,您就能針對特定的文件風格創造獨特的視覺效果。 每個屬性都控制反射的不同方面,從位置和角度到透明度和顏色。 以下列表詳細介紹了每個房產:
哪些屬性控制反射外觀?
-
SchemeColor:取得或設定反射效果的配色方案。 使用任何顏色對水或金屬表面效果的反射進行著色。 -
HorizontalSkewAngle:取得或設定水平傾斜角度(單位為度)。 創造透視效果,讓倒影退到遠方。 -
HorizontalScalingFactor:取得或設定水平縮放係數。 低於 100 的值會壓縮; 價值超過 100 伸展。 -
DistanceFromText:取得或設定以點(1/72 英吋)為單位的距離。 較小的數值會產生緊密的反映; 較大值模擬遙遠的表面。 -
DirectionAngle:取得或設定方向角度(單位為度)。 判定視光源方向。 -
FadeDirectionAngle:取得或設定淡入淡出方向(單位為度)。 控制地板反射的垂直漸變或水效果的角度漸變。 -
EndPosition:取得或設定結尾位置。 確定倒影完全淡出的位置。 -
StartPosition:取得或設定起始位置。 通常 0 要緊接在文字下方開始。 -
EndingOpacity:取得或設定結束不透明度。 較低的數值會產生微妙的反射,逐漸變得透明。 -
VerticalScalingFactor:取得或設定垂直縮放係數。 負數值翻轉文字; 大小控制高度。 -
StartingOpacity:取得或設定初始不透明度。 較高的數值會產生較強的初步反映。 -
Alignment:取得或設定對齊方式。 從各種選項中選擇相對於文字的倒影位置。 -
BlurRadius:取得或設定模糊半徑(單位為點,即 1/72 英吋)。 較高的值會產生較柔和、較散的反射。 VerticalSkewAngle:取得或設定垂直傾斜角度(單位為度)。 用於建立斜面反射效果。
如何建立自訂反射效果?
自訂反射效果可讓您配合組織的品牌或建立獨特的視覺風格。 以下範例展示了金色的反光,搭配特定的定位和不透明度設定,為證書、獎項或優質文件標頭創造出專業的外觀。
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-reflection-effect.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection()
{
Alignment = RectangleAlignmentValues.BottomLeft,
BlurRadius = 5,
DirectionAngle = 90,
DistanceFromText = 5,
EndingOpacity = 100,
EndPosition = 10,
FadeDirectionAngle = 90,
HorizontalScalingFactor = 100,
HorizontalSkewAngle = 0,
SchemeColor = IronWord.Models.Color.Gold,
StartingOpacity = 0,
StartPosition = 0,
VerticalScalingFactor = -100,
VerticalSkewAngle = 0,
},
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Customized reflection"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedReflectionEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection() With {
.Alignment = RectangleAlignmentValues.BottomLeft,
.BlurRadius = 5,
.DirectionAngle = 90,
.DistanceFromText = 5,
.EndingOpacity = 100,
.EndPosition = 10,
.FadeDirectionAngle = 90,
.HorizontalScalingFactor = 100,
.HorizontalSkewAngle = 0,
.SchemeColor = IronWord.Models.Color.Gold,
.StartingOpacity = 0,
.StartPosition = 0,
.VerticalScalingFactor = -100,
.VerticalSkewAngle = 0
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Customized reflection"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedReflectionEffect.docx")
使用自訂屬性可以達到哪些結果?
上面的自訂倒影範例產生了獨特的金色倒影,增強了文件的高級感。 透過調整從 0% 到 100% 的不透明度漸層,倒影創造出一種反向漸層效果,當倒影遠離文字時會變得更強。 此技術對於建立顯眼的標題或強調重要公告非常有效。
反射效果的最佳實作
在專業文件中實現反射效果時,請考慮這些準則:
含蓄往往最有效:對於商業文件,使用較低的結尾不透明度值 (20-40%) 來創造微妙的反射效果,既能增強效果,又不會分散注意力。 將較強烈的效果保留給行銷材料或簡報,因為視覺效果是最重要的。
匹配您的文件風格:使反射屬性與您的文件整體設計一致。 正式文件可從簡單的垂直反射中獲益,並將模糊程度降到最低,而創意材料則可利用傾斜角度和彩色反射達到藝術效果。
效能考量:具有高模糊半徑值的複雜反射效果可能會增加檔案大小和處理時間。對於具有大量反射元素的文件,請測試效能並相應調整屬性。
無障礙意識:請記住,反光等裝飾效果應該增強而不是取代清晰的溝通。 確保您的主要文字保持高可讀性,尤其是在建立需要符合無障礙標準的文件時。
常見問題解答
如何在 C# 中為文字加入反射效果?
透過 IronWord,您可以建立一個 TextStyle 物件,並在 ReflectionEffect 屬性中填入一個 Reflection 物件,以加入反射效果。只要實體化 Reflection 類別,並將其指定給文字樣式即可 - IronWord 會自動處理所有複雜的渲染。
應用文字反射效果的最簡單方法是什麼?
最快速的方法是使用 IronWord 的單行實作:new IronWord.WordDocument().AddText("Your Text").Style = new IronWord.Models.TextStyle(){ TextEffect = new IronWord.Models.TextEffect(){ ReflectionEffect = new IronWord.Models.Reflection() }。}.這會立即套用預設的反射效果。
我可以自訂反射效果的屬性嗎?
是的,IronWord 的 Reflection 類別提供各種可設定的屬性來調整反射的外觀,包括不透明度淡化、與文字的距離、模糊設定以及透明度等級。您可以微調這些屬性,針對您特定的設計需求,創造獨特的視覺效果。
預設的反射效果是什麼樣子?
IronWord 的預設反射功能可在文字下方建立微妙的鏡像,並自動淡化不透明度。預設組態包含適當的模糊與透明度設定,可與各種字型大小與樣式完美搭配,因此適用於大多數的商業文件,無須額外的客製化設定。
為什麼要使用 TextStyle 物件來做反射效果?
IronWord 中的 TextStyle 物件是所有文字格式化的中央配置點。這種樣式與內容分離的方式,可讓您在多個文字元素中重複使用相同的反射效果,確保一致性,並可透過修改單一樣式物件,輕鬆地在全局範圍內更新效果。
哪些類型的文件可以從反射效果中獲益?
反射效果對於標題、標題以及強調專業文件中的關鍵資訊特別有效。IronWord 的倒影功能可模擬文字置於光滑的表面上,創造出優雅的外觀,增強文件的呈現效果,並吸引讀者注意重要的元素。

