如何为文本添加阴影效果

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

文字阴影效果是一种视觉增强技术,用于创建文字元素的深度和区别。应用时,它会在原始文本后面引入一个文本的复制版本,略微偏移以呈现阴影的效果。这种被称为阴影的辅助文本可以通过多种方式进行调整,以达到不同的视觉效果。

适用于的C# NuGet库

安装使用 NuGet

Install-Package IronWord
适用于的C# NuGet库

安装使用 NuGet

Install-Package IronWord
Java PDF JAR

下载 DLL

下载DLL

手动安装到你的项目中

开始在您的项目中使用IronPDF,并立即获取免费试用。

第一步:
green arrow pointer

查看 IronWordNuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。

适用于的C# NuGet库 nuget.org/packages/IronWord/
Install-Package IronWord

添加阴影效果

要为文本指定阴影效果,请创建TextStyle对象,并在 ShadowEffect 属性中填入一个Shadow对象。最后,将 TextStyle 对象赋值给 TextEffect 属性,从而添加具有该样式的新文本。

:path=/static-assets/word/content-code-examples/how-to/text-effect-shadow-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()
{
    ShadowEffect = Shadow.OuterShadow1,
};

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

// Export new Word document
doc.SaveAs("shadowEffect.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 {.ShadowEffect = Shadow.OuterShadow1}

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

' Export new Word document
doc.SaveAs("shadowEffect.docx")
VB   C#
添加阴影效果

阴影效果属性

除了分配预定义的阴影值外,还可以配置阴影效果的所有属性。这为以任何可能的方式定制阴影效果提供了非常灵活的选择。请参阅下面的属性及其说明:

  • 对齐:获取或设置阴影的对齐方式。
  • BlurRadius:获取或设置阴影效果的模糊半径。模糊半径的单位是点 (1/72 英寸).
  • DirectionAngle:获取或设置阴影效果的方向角。方向角以度为单位。
  • DistanceFromText:获取或设置阴影效果与文本或对象的距离。距离的单位是点 (1/72 英寸).
  • 水平缩放因子:获取或设置阴影效果的水平缩放因子。
  • HorizontalSkewAngle:获取或设置阴影效果的水平倾斜角度。倾斜角度的单位为度。
  • SchemeColor:获取或设置阴影效果的方案颜色。
  • VerticalScalingFactor:获取或设置阴影效果的垂直缩放因子。

  • VerticalSkewAngle:获取或设置阴影效果的垂直倾斜角度。倾斜角度的单位为度。
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-shadow-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()
{
    ShadowEffect = new Shadow()
    {
        Alignment = RectangleAlignmentValues.BottomLeft,
        BlurRadius = 5,
        DirectionAngle = 45,
        DistanceFromText = 3,
        HorizontalScalingFactor = 100,
        VerticalScalingFactor = 100,
        HorizontalSkewAngle = 0,
        SchemeColor = IronWord.Models.Color.Aqua,
        VerticalSkewAngle = 0,
    },
};

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

// Export new Word document
doc.SaveAs("customizedShadowEffect.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 {
	.ShadowEffect = New Shadow() With {
		.Alignment = RectangleAlignmentValues.BottomLeft,
		.BlurRadius = 5,
		.DirectionAngle = 45,
		.DistanceFromText = 3,
		.HorizontalScalingFactor = 100,
		.VerticalScalingFactor = 100,
		.HorizontalSkewAngle = 0,
		.SchemeColor = IronWord.Models.Color.Aqua,
		.VerticalSkewAngle = 0
	}
}

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

' Export new Word document
doc.SaveAs("customizedShadowEffect.docx")
VB   C#
自定义阴影效果