如何為文字添加漸變效果
在文字上添加漸變效果涉及在文字的字符或背景上應用顏色的平滑過渡,從一種顏色到另一種或多種顏色的漸變。這種效果增加了文字的深度、視覺吸引力和動態外觀,使其更加突出並增強其美學外觀。漸變效果可以是線性的 (顏色直線過渡) 或徑向 (顏色從中心點向外過渡)
如何向文本添加漸變效果
- 下載允許為文字新增漸層的 C# 函式庫
- 將文字效果應用到新創建或現有的文字上
- 使用預設的漸變效果,方法是使用靜態命名實例 漸變 類別
- 配置 漸變Effect 自訂文字輪廓的屬性
- 將編輯後的 Word 文件導出為新文件
安裝與 NuGet
Install-Package IronWord
立即開始在您的專案中使用IronPDF,並享受免費試用。
查看 IronWord 上 Nuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變。
Install-Package IronWord
新增漸變效果
要指定文字的漸變效果,請創建 TextStyle 對象,並以 Gradient 對象填充 GradientEffect 屬性。最後,通過將 TextStyle 對象指定給 TextEffect 屬性來添加新的文本樣式。
:path=/static-assets/word/content-code-examples/how-to/text-effect-gradient-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()
{
GradientEffect = Gradient.DefaultGray,
};
// Add text with style
doc.AddText("Hello World").Style = textStyle;
// Export new Word document
doc.SaveAs("gradientEffect.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 {.GradientEffect = Gradient.DefaultGray}
' Add text with style
doc.AddText("Hello World").Style = textStyle
' Export new Word document
doc.SaveAs("gradientEffect.docx")
漸層效果屬性
漸層效果提供一系列可調整的屬性,以滿足不同的設計需求。請參閱以下清單以瞭解每個屬性的詳細描述:
GradientStop
- Color: 獲取或設置漸層停止的色系顏色。
- StopPoint: 獲取或設置漸層停止的位置。
漸層停止是漸層中定義特定顏色的點。
Gradient
- StopPoints: 獲取或設置定義漸層填充的漸層停止列表。
- LinearShadeScaled: 獲取或設置指示線性陰影是否縮放的值。
- LinearShadeAngle: 獲取或設置線性陰影的角度。
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-gradient-effect.cs
using IronWord;
using IronWord.Models;
using System.Collections.Generic;
// Create new Word document
WordDocument doc = new WordDocument();
// Create gradient stops
GradientStop firstGradientStop = new GradientStop()
{
Color = IronWord.Models.Color.Aqua,
StopPoint = 1
};
GradientStop secondGradientStop = new GradientStop()
{
Color = IronWord.Models.Color.OrangeRed,
StopPoint = 10
};
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
GradientEffect = new Gradient()
{
StopPoints = new List<GradientStop> { firstGradientStop, secondGradientStop },
LinearShadeAngle = 45,
LinearShadeScaled = true,
}
};
// Add text with style
doc.AddText("Hello World").Style = textStyle;
// Export new Word document
doc.SaveAs("customizedGradientEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports System.Collections.Generic
' Create new Word document
Private doc As New WordDocument()
' Create gradient stops
Private firstGradientStop As New GradientStop() With {
.Color = IronWord.Models.Color.Aqua,
.StopPoint = 1
}
Private secondGradientStop As New GradientStop() With {
.Color = IronWord.Models.Color.OrangeRed,
.StopPoint = 10
}
' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.GradientEffect = New Gradient() With {
.StopPoints = New List(Of GradientStop) From {firstGradientStop, secondGradientStop},
.LinearShadeAngle = 45, .LinearShadeScaled = True
}
}
' Add text with style
doc.AddText("Hello World").Style = textStyle
' Export new Word document
doc.SaveAs("customizedGradientEffect.docx")