如何为文本添加渐变效果

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对象,并在 GradientEffect 属性中填入一个Gradient对象。最后,将 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#
添加渐变效果

梯度效果属性

渐变效果提供一系列可调属性,以满足不同的设计要求。有关各属性的详细说明,请参见以下列表:

GradientStop

  • **颜色获取或设置渐变止点的方案颜色。
  • 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#
定制渐变效果