BrushCreateLinearGradient(Single, ColorF, ColorF, WorkingColorSpace) Method

Creates a linear gradient Brush that blends from one color to another along a straight line. The line is specified by an angle only, whereas the actual start and end points are determined by the bounding rectangle of the current Path in each session.
See the Examples section of the CreateLinearGradient(Single, Color32, Color32, WorkingColorSpace) overload for an example with image.

Definition

Namespace: KGySoft.Drawing.Shapes
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
C#
public static Brush CreateLinearGradient(
	float angle,
	ColorF startColor,
	ColorF endColor,
	WorkingColorSpace workingColorSpace = WorkingColorSpace.Default
)

Parameters

angle  Single
The angle of the gradient line in degrees. The angle is measured clockwise from the positive x-axis.
startColor  ColorF
The starting color of the gradient.
endColor  ColorF
The end color of the gradient.
workingColorSpace  WorkingColorSpace  (Optional)
Determines the color space in which the gradient is calculated. This parameter is optional.
Default value: Default, which means Srgb for this overload.

Return Value

Brush
A linear gradient Brush that uses the specified parameters.

Remarks

This overload creates a gradient with dynamic coordinates, applying the gradient automatically to the bounds of each Path. To use fix coordinates instead, use the overloads with a startPoint and endPoint parameters, such as the CreateLinearGradient(PointF, PointF, Color32, Color32, GradientWrapMode, WorkingColorSpace) overload.

The workingColorSpace parameter affects only the color interpolation, not the blending with the background, which is determined by the color space of the target bitmap data (or by DrawingOptions.Quantizer, if specified).

In this overload the default value of workingColorSpace maps to WorkingColorSpace.Linear, because the ColorF type represents a color in the linear color space. When creating a monochromatic gradient, specifying Srgb can be better, because then the perceived mid-tone brightness will be at the middle of the gradient. Otherwise, using Linear may be more appropriate, so the transition between the colors will seem more "natural".

See Also