BitmapDataFactoryCreateLinearGradient(Size, Single, Color64, Color64, 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. The line is specified by an angle only, and the actual start and end points are calculated automatically so they stretch from one edge of the bitmap to the opposite edge.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.1
C#
public static IReadableBitmapData CreateLinearGradient(
	Size size,
	float angle,
	Color64 startColor,
	Color64 endColor,
	WorkingColorSpace workingColorSpace = WorkingColorSpace.Default
)

Parameters

size  Size
The size, in pixels, of the bitmap data to create.
angle  Single
The angle of the gradient line in degrees. The angle is measured clockwise from the positive x-axis.
startColor  Color64
The color at the start of the gradient.
endColor  Color64
The color at the end of the gradient.
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 calculates the start/end points of the gradient automatically, which stretches from one edge to another. To specify custom points, use the overloads with a startPoint and endPoint parameters.

In this overload the default value of workingColorSpace maps to WorkingColorSpace.Srgb, because the Color64 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