如何向文本添加漸變效果

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

文字上的漸變效果涉及在字符或文字背景上應用顏色的平滑過渡,從一種顏色過渡到另一種顏色或多種顏色。 此效果增加了文字的深度、視覺吸引力和動態外觀,使文字更加突出並增強了其美觀。 漸變效果可以是線性的(顏色直線過渡)或徑向(顏色從中心點向外過渡)

快速開始使用IronWord

立即在您的專案中使用IronWord,並享受免費試用。

第一步:
green arrow pointer


添加漸變效果

要為文字指定漸變效果,請創建 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")
VB   C#
新增漸變效果

漸變效果屬性

漸層效果提供了一系列可調整的屬性,以滿足多樣的設計需求。 請參閱下列列表以獲得每個屬性的詳細描述:

漸變停止

  • 顏色:獲取或設置漸變停靠點的配色方案。
  • StopPoint:獲取或設置漸變停止的位置。

    漸變停點是在漸變中定義特定顏色的點。

    梯度

  • 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")
VB   C#
自定漸變效果