BitmapDataFactoryCreateLinearGradient(Int32, Int32, PointF, PointF, Color32, Color32, GradientWrapMode, WorkingColorSpace) Method

Creates a read-only bitmap data with no actual underlying buffer, containing a linear gradient that transitions between two colors along a straight line.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.1
C#
public static IReadableBitmapData CreateLinearGradient(
	int width,
	int height,
	PointF startPoint,
	PointF endPoint,
	Color32 startColor,
	Color32 endColor,
	GradientWrapMode wrapMode = GradientWrapMode.Stop,
	WorkingColorSpace workingColorSpace = WorkingColorSpace.Default
)

Parameters

width  Int32
The width of the bitmap data to create, in pixels.
height  Int32
The height of the bitmap data to create, in pixels.
startPoint  PointF
The starting point of the gradient.
endPoint  PointF
The end point of the gradient.
startColor  Color32
The color at the start of the gradient.
endColor  Color32
The color at the end of the gradient.
wrapMode  GradientWrapMode  (Optional)
Determines how the gradient is treated outside the gradient area. This parameter is optional.
Default value: Stop.
workingColorSpace  WorkingColorSpace  (Optional)
The color space used for gradient interpolation. This parameter is optional.
Default value: Default, which means Srgb for this overload.

Return Value

IReadableBitmapData
An IReadableBitmapData instance containing the generated linear gradient image.

Remarks

This overload creates a gradient specified by coordinates. To automatically apply the gradient to the bounds of the entire bitmap, use the overloads with an angle parameter.

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".

  Note

Though the returned bitmap does not allocate an internal buffer and calculates every pixel dynamically when they are accessed, operations on the result that return a new bitmap data (e.g. Clone, Resize, ToGrayscale, etc.) end up allocating a pixel buffer.

See Also