如何向文本添加漸變效果

查克尼思·賓
查克尼思·賓
2024年6月24日
已更新 2024年12月10日
分享:
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")
$vbLabelText   $csharpLabel
新增漸層效果

漸變效果屬性

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

漸變停止點

  • 顏色:獲取或設定漸變停止點的色彩方案。
  • 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")
$vbLabelText   $csharpLabel
自訂漸變效果
查克尼思·賓
軟體工程師
Chaknith 致力於 IronXL 和 IronBarcode。他在 C# 和 .NET 方面擁有豐富的專業知識,協助改進軟體並支持客戶。他從用戶互動中獲得的洞察力有助於提高產品、文檔和整體體驗。