Class LinearGradientBrush
Namespace: Aspose.Imaging.Brushes
Assembly: Aspose.Imaging.dll (25.2.0)
Encapsulates a Aspose.Imaging.Brush with a linear gradient. This class cannot be inherited.
[JsonObject(MemberSerialization.OptIn)]
public sealed class LinearGradientBrush : LinearGradientBrushBase, IDisposable
Inheritance
object ← DisposableObject ← Brush ← TransformBrush ← LinearGradientBrushBase ← LinearGradientBrush
Implements
Inherited Members
LinearGradientBrushBase.Rectangle, LinearGradientBrushBase.Angle, LinearGradientBrushBase.IsAngleScalable, LinearGradientBrushBase.GammaCorrection, TransformBrush.ResetTransform(), TransformBrush.MultiplyTransform(Matrix), TransformBrush.MultiplyTransform(Matrix, MatrixOrder), TransformBrush.TranslateTransform(float, float), TransformBrush.TranslateTransform(float, float, MatrixOrder), TransformBrush.ScaleTransform(float, float), TransformBrush.ScaleTransform(float, float, MatrixOrder), TransformBrush.RotateTransform(float), TransformBrush.RotateTransform(float, MatrixOrder), TransformBrush.WrapMode, TransformBrush.Transform, TransformBrush.IsTransformChanged, Brush.DeepClone(), Brush.Equals(object), Brush.GetHashCode(), Brush.Opacity, DisposableObject.Dispose(), DisposableObject.Disposed, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
LinearGradientBrush(RectangleF, Color, Color, float, bool)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, float angle, bool isAngleScalable)
Parameters
rect
RectangleF
The rectangle.
color1
Color
The color1.
color2
Color
The color2.
angle
float
The angle.
isAngleScalable
bool
if set to true
[is angle scalable].
LinearGradientBrush(Rectangle, Color, Color, float, bool)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(Rectangle rect, Color color1, Color color2, float angle, bool isAngleScalable)
Parameters
rect
Rectangle
The rectangle.
color1
Color
The color1.
color2
Color
The color2.
angle
float
The angle.
isAngleScalable
bool
if set to true
[is angle scalable].
LinearGradientBrush(RectangleF, Color, Color, float)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, float angle)
Parameters
rect
RectangleF
The rectangle.
color1
Color
The color1.
color2
Color
The color2.
angle
float
The angle.
LinearGradientBrush(Rectangle, Color, Color, float)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(Rectangle rect, Color color1, Color color2, float angle)
Parameters
rect
Rectangle
The rectangle.
color1
Color
The color1.
color2
Color
The color2.
angle
float
The angle.
LinearGradientBrush(PointF, PointF, Color, Color)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(PointF point1, PointF point2, Color color1, Color color2)
Parameters
point1
PointF
The point1.
point2
PointF
The point2.
color1
Color
The color1.
color2
Color
The color2.
LinearGradientBrush(Point, Point, Color, Color)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class.
public LinearGradientBrush(Point point1, Point point2, Color color1, Color color2)
Parameters
point1
Point
The point1.
point2
Point
The point2.
color1
Color
The color1.
color2
Color
The color2.
Examples
The following example shows how to create a grayscale copy of an existing frame and add it to a TIFF image.```csharp [C#]
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// Create a permanent, not temporary file source.
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "multipage.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
// The linear gradient from the left-top to the right-bottom corner of the image.
Aspose.Imaging.Brushes.LinearGradientBrush brush =
new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(tiffImage.Width, tiffImage.Height),
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green);
// Fill the active frame with a linear gradient brush.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(tiffImage.ActiveFrame);
gr.FillRectangle(brush, tiffImage.Bounds);
// Grayscale options
Aspose.Imaging.ImageOptions.TiffOptions createTiffFrameOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffFrameOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
createTiffFrameOptions.Photometric = Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.MinIsBlack;
createTiffFrameOptions.BitsPerSample = new ushort[] { 8 };
// Create a grayscale copy of the active frame.
// The pixel data is preserved but converted to the desired format.
Aspose.Imaging.FileFormats.Tiff.TiffFrame grayscaleFrame = Aspose.Imaging.FileFormats.Tiff.TiffFrame.CreateFrameFrom(tiffImage.ActiveFrame, createTiffFrameOptions);
// Add the newly created frame to the TIFF image.
tiffImage.AddFrame(grayscaleFrame);
tiffImage.Save();
}
### <a id="Aspose_Imaging_Brushes_LinearGradientBrush__ctor"></a> LinearGradientBrush\(\)
Initializes a new instance of the Aspose.Imaging.Brushes.LinearGradientBrush class with default parameters.
The starting color is black, the ending color is white, the angle is 45 degrees and the rectangle is located in (0,0) with size (1,1).
```csharp
public LinearGradientBrush()
Properties
Blend
Gets or sets a Aspose.Imaging.Blend that specifies positions and factors that define a custom falloff for the gradient.
public Blend Blend { get; set; }
Property Value
EndColor
Gets or sets the ending gradient color.
public Color EndColor { get; set; }
Property Value
InterpolationColors
Gets or sets a Aspose.Imaging.ColorBlend that defines a multicolor linear gradient.
[Obsolete("This property is not used anymore in this class. Use instance of the LinearMulticolorGradientBrush class instead.")]
[JsonIgnore]
public ColorBlend InterpolationColors { get; set; }
Property Value
LinearColors
Gets or sets the starting and ending colors of the gradient.
[Obsolete("Use StartColor and EndColor properties instead.")]
[JsonIgnore]
public Color[] LinearColors { get; set; }
Property Value
Color[]
StartColor
Gets or sets the starting gradient color.
public Color StartColor { get; set; }
Property Value
Methods
SetBlendTriangularShape(float)
Creates a linear gradient with a center color and a linear falloff to a single color on both ends.
public void SetBlendTriangularShape(float focus)
Parameters
focus
float
A value from 0 through 1 that specifies the center of the gradient (the point where the gradient is composed of only the ending color).
SetBlendTriangularShape(float, float)
Creates a linear gradient with a center color and a linear falloff to a single color on both ends.
public void SetBlendTriangularShape(float focus, float scale)
Parameters
focus
float
A value from 0 through 1 that specifies the center of the gradient (the point where the gradient is composed of only the ending color).
scale
float
A value from 0 through1 that specifies how fast the colors falloff from the starting color to focus
(ending color)
SetSigmaBellShape(float)
Creates a gradient falloff based on a bell-shaped curve.
public void SetSigmaBellShape(float focus)
Parameters
focus
float
A value from 0 through 1 that specifies the center of the gradient (the point where the starting color and ending color are blended equally).
SetSigmaBellShape(float, float)
Creates a gradient falloff based on a bell-shaped curve.
public void SetSigmaBellShape(float focus, float scale)
Parameters
focus
float
A value from 0 through 1 that specifies the center of the gradient (the point where the gradient is composed of only the ending color).
scale
float
A value from 0 through 1 that specifies how fast the colors falloff from the focus
.