如何为文本添加渐变效果

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#
定制渐变效果