如何在 C# | IronWord 中為文字加入反射效果

如何在 C# 中為文字添加反射效果

This article was translated from English: Does it need improvement?
Translated
View the article in English

文字反射效果是一種視覺增強技術,它會在文字的原始形狀下方創造出類似鏡子的影像。 這種效果模擬了文字在表面上的反射,通常能為設計增添深度和真實感。

快速入門:在 C# 中為文字套用反射效果

使用 IronWord,只需一行程式碼,即可將預設的反射效果套用至任何文字。 開發者可以立即上手使用—無需複雜的設定或樣板程式碼。

Nuget Icon立即開始使用 NuGet 建立 PDF 檔案:

  1. 使用 NuGet 套件管理器安裝 IronWord

    PM > Install-Package IronWord

  2. 複製並運行這段程式碼。

    new IronWord.WordDocument().AddText("Quick Text").Style = new IronWord.Models.TextStyle(){ TextEffect = new IronWord.Models.TextEffect(){ ReflectionEffect = new IronWord.Models.Reflection() } };
  3. 部署到您的生產環境進行測試

    立即開始在您的專案中使用 IronWord,免費試用!
    arrow pointer

加入反射效果

若要指定文字的反射效果,請建立TextStyle對象,並使用Reflection物件填入ReflectionEffect屬性。 最後,透過將TextStyle物件指派給TextEffect屬性來新增具有該樣式的新文字。

: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(),
};

// Add text with style
doc.AddText("Hello World").Style = textStyle;

// Export new Word document
doc.SaveAs("reflectionEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Private doc As New WordDocument()

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {.ReflectionEffect = New Reflection()}

' Add text with style
doc.AddText("Hello World").Style = textStyle

' Export new Word document
doc.SaveAs("reflectionEffect.docx")
$vbLabelText   $csharpLabel
加入反射效果

反射效應特性

反射效果提供了一系列可調節的屬性,以滿足不同的設計需求。 以下列表詳細介紹了每個房產:

  • SchemeColor :取得或設定反射效果的配色方案顏色。
  • HorizontalSkewAngle :取得或設定反射效果的水平傾斜角度。 傾斜角度以度為單位。
  • HorizontalScalingFactor :取得或設定反射效果的水平縮放因子。
  • DistanceFromText :取得或設定反射效果與文字或物件之間的距離。 距離以磅(1/72 英吋)為單位。
  • DirectionAngle :取得或設定反射效果的方向角度。 方向角以度為單位。
  • FadeDirectionAngle :取得或設定反射效果的淡入淡出方向。
  • EndPosition :取得或設定反射效果的結束位置。
  • StartPosition :取得或設定反射效果的起始位置。
  • 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,
    },
};

// Add text with style
doc.AddText("Customized reflection").Style = textStyle;

// Export new Word document
doc.SaveAs("customizedReflectionEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums

' Create new Word document
Private doc As New WordDocument()

' Create and configure text style
Private 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
	}
}

' Add text with style
doc.AddText("Customized reflection").Style = textStyle

' Export new Word document
doc.SaveAs("customizedReflectionEffect.docx")
$vbLabelText   $csharpLabel
客製化反射效果

常見問題解答

如何使用 C# 為 Word 文件中的文字加入反射效果?

您可以下載 IronWord 函式庫,使用 C# 為 Word 文件中的文字加入反射效果。首先建立一個 `TextStyle` 物件,將其 `ReflectionEffect` 屬性填入一個 `Reflection` 物件,並依您的喜好自訂屬性。最後,匯出已套用反射效果的 Word 文件。

在 IronWord 中,哪些屬性可以調整為反射效果?

在 IronWord 中,您可以調整 `SchemeColor`、`HorizontalSkewAngle`、`HorizontalScalingFactor`、`DistanceFromText`、`DirectionAngle`、`FadeDirectionAngle` 等屬性、終止位置」、「開始位置」、「終止透明度」、「垂直縮放因子」、「開始透明度」、「對齊」、「模糊半徑」和「垂直傾斜角度」,以自訂反射效果。

如何自訂反射效果與文字的距離?

在 IronWord 中,使用 `DistanceFromText` 屬性來設定反射效果與文字的距離。這個距離是以點(1/72 英吋)為單位指定的,讓您可以控制倒影與原始文字的距離。

我可以調整 IronWord 中反射效果的不透明度嗎?

是的,IronWord 中反射效果的不透明度可以使用 `StartingOpacity` 和 `EndingOpacity` 屬性進行自訂。這些屬性可讓您定義反射開始和結束時的透明度,讓您控制其視覺效果。

反射效果中的 `HorizontalSkewAngle` 有何作用?

IronWord 中的「HorizontalSkewAngle」屬性可設定反射效果的水平偏斜角度。此屬性以度為單位,藉由水平傾斜來改變倒影的外觀。

如何開始在 C# 中為文字加入反射效果?

首先下載 IronWord 函式庫。建立一個 `TextStyle` 物件,並將 `ReflectionEffect` 屬性填入一個 `Reflection` 物件。使用可用的屬性自訂效果,並套用到您的文字上。

是否可以在 IronWord 中調整反射效果的模糊度?

是的,您可以在 IronWord 中透過設定 `BlurRadius` 屬性來調整反射效果的模糊程度。這個值是以點(1/72 英吋)為單位指定的,讓您可以控制倒影的柔和度。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 27,129 | Version: 2025.11 剛發表