如何為文字添加陰影效果

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#
添加陰影效果

陰影效應屬性

除了指定預定的陰影值之外,陰影效應的所有屬性都可以配置。這為自訂陰影效應提供了一個非常靈活的選項。請參閱以下屬性及其描述:

  • Alignment:獲取或設置陰影的對齊方式。
  • BlurRadius:獲取或設置陰影效應的模糊半徑。模糊半徑以點數指定。 (1/72英寸).
  • DirectionAngle: 獲取或設置陰影效果的方向角度。方向角度以角度為單位指定。
  • DistanceFromText: 獲取或設置陰影效果與文字或物件之間的距離。距離以點為單位指定。 (1/72英寸).
  • HorizontalScalingFactor:獲取或設置陰影效果的水平縮放因子。
  • 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#
自訂陰影效果