Cómo añadir un efecto degradado al texto

Chaknith Bin
Chaknith Bin
24 de junio, 2024
Actualizado 10 de diciembre, 2024
Compartir:
This article was translated from English: Does it need improvement?
Translated
View the article in English

Un efecto de degradado en el texto consiste en aplicar una transición suave de colores a través de los caracteres o el fondo del texto, creando una mezcla de un color a otro o de varios colores. Este efecto añade profundidad, interés visual y un aspecto dinámico al texto, haciéndolo destacar y mejorando su apariencia estética. Los efectos de degradado pueden ser lineales (los colores transicionan en línea recta) o radiales (los colores transicionan desde un punto central hacia afuera).

Empiece a utilizar IronWord

Comience a usar IronWord en su proyecto hoy con una prueba gratuita.

Primer Paso:
green arrow pointer


Añadir efecto degradado

Para especificar el efecto de gradiente para el texto, cree el objeto TextStyle y complete la propiedad GradientEffect con un objeto Gradient. Finalmente, añade nuevo texto con el estilo asignando el objeto TextStyle a la propiedad 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
Agregar efecto de degradado

Propiedades del efecto degradado

El efecto degradado ofrece una gama de atributos ajustables para satisfacer diversos requisitos de diseño. Consulte la siguiente lista para obtener descripciones detalladas de cada propiedad:

DetenerDegradado

  • Color: Obtiene o establece el color del esquema del punto de parada del gradiente.
  • StopPoint: Obtiene o establece la posición del punto de detención del degradado.

    Las paradas de gradiente son puntos dentro de un gradiente donde se define un color específico.

    Gradiente

  • StopPoints: Obtiene o establece la lista de puntos de parada de gradiente que definen el relleno de gradiente.
  • LinearShadeScaled: Obtiene o establece un valor que indica si el degradado lineal está escalado.
  • LinearShadeAngle: Obtiene o establece el ángulo de la sombra lineal.
: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
Efecto de gradiente personalizado
Chaknith Bin
Ingeniero de software
Chaknith trabaja en IronXL e IronBarcode. Tiene una gran experiencia en C# y .NET, ayudando a mejorar el software y a apoyar a los clientes. Sus conocimientos de las interacciones con los usuarios contribuyen a mejorar los productos, la documentación y la experiencia general.