如何在 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`、`EndPosition`、`StartPosition`、`EndingOpacity`、`VerticalScalingFactor`、`StartingOpacity`、`Alignment`、`BlurRadius` 和 `VerticalSkewAngle` 等属性,以自定义反射效果。

如何自定义反射效果与文本的距离?

在IronWord中,使用`DistanceFromText`属性设置反射效果与文本的距离(以点为单位),控制反射与原始文本的距离。

我可以在 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 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 27,129 | Version: 2025.11 刚刚发布