public static Brush CreateLinearGradient(
float angle,
Color32 startColor,
Color32 endColor,
WorkingColorSpace workingColorSpace = WorkingColorSpace.Default
)Public Shared Function CreateLinearGradient (
angle As Single,
startColor As Color32,
endColor As Color32,
Optional workingColorSpace As WorkingColorSpace = WorkingColorSpace.Default
) As Brushpublic:
static Brush^ CreateLinearGradient(
float angle,
Color32 startColor,
Color32 endColor,
WorkingColorSpace workingColorSpace = WorkingColorSpace::Default
)static member CreateLinearGradient :
angle : float32 *
startColor : Color32 *
endColor : Color32 *
?workingColorSpace : WorkingColorSpace
(* Defaults:
let _workingColorSpace = defaultArg workingColorSpace WorkingColorSpace.Default
*)
-> Brush 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.Srgb, because the Color32 type represents a color in the sRGB 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".
The following example demonstrates how to create a horizontal linear gradient brush that blends from white to black, adjusted always to the currently filled shape:
public IReadWriteBitmapData CreateBitmap()
{
var bitmap = BitmapDataFactory.CreateBitmapData(100, 150);
bitmap.Clear(Color.Cyan);
// Zero angle means horizontal gradient
var brush = Brush.CreateLinearGradient(angle: 0f, Color.White, Color.Black);
// Filling the same ellipse three times with different offsets
foreach (int offset in new[] { -50, 0, 50 })
{
var options = new DrawingOptions
{
AntiAliasing = true,
Transformation = TransformationMatrix.CreateTranslation(offset, offset + 50)
};
bitmap.FillEllipse(brush, new Rectangle(0, 0, 100, 50), options);
}
return bitmap;
}The example above produces the result below. Note that the gradient always starts from the left edge of the ellipse and ends at the right edge, regardless of the ellipse's location.
As a contrast, see the examples at the GradientWrapMode enumeration, where the gradients always use specific start and end points.
