Method CreateGradientStopCollection
- Namespace
- PaintDotNet.Direct2D1
- Assembly
- PaintDotNet.Windows.dll
CreateGradientStopCollection(ReadOnlySpan<GradientStop>, GradientStopGamma, ExtendMode)
Creates an IGradientStopCollection from the specified array of GradientStop structures.
IGradientStopCollection CreateGradientStopCollection(ReadOnlySpan<GradientStop> gradientStops, GradientStopGamma colorInterpolationGamma = GradientStopGamma.Srgb, ExtendMode extendMode = ExtendMode.Clamp)
Parameters
gradientStops
ReadOnlySpan<GradientStop>The array of GradientStop structures.
colorInterpolationGamma
GradientStopGammaThe space in which color interpolation between the gradient stops is performed.
extendMode
ExtendModeThe behavior of the gradient outside the [0,1] normalized range.
Returns
- IGradientStopCollection
The new gradient stop collection.
CreateGradientStopCollection(ReadOnlySpan<GradientStop>, DeviceColorSpace, DeviceColorSpace, BufferPrecision, ExtendMode, ColorInterpolationMode)
Creates a gradient stop collection, enabling the gradient to contain color channels with values outside of [0,1] and also enabling rendering to a high-color render target with interpolation in sRGB space.
IGradientStopCollection CreateGradientStopCollection(ReadOnlySpan<GradientStop> straightAlphaGradientStops, DeviceColorSpace preInterpolationSpace, DeviceColorSpace postInterpolationSpace, BufferPrecision bufferPrecision = BufferPrecision.Float32, ExtendMode extendMode = ExtendMode.Clamp, ColorInterpolationMode colorInterpolationMode = ColorInterpolationMode.Premultiplied)
Parameters
straightAlphaGradientStops
ReadOnlySpan<GradientStop>An array of color values and offsets.
preInterpolationSpace
DeviceColorSpaceSpecifies both the input color space and the space in which the color interpolation occurs.
postInterpolationSpace
DeviceColorSpaceThe color space that colors will be converted to after interpolation occurs.
bufferPrecision
BufferPrecisionThe precision of the texture used to hold interpolated values.
extendMode
ExtendModeDefines how colors outside of the range defined by the stop collection are determined.
colorInterpolationMode
ColorInterpolationModeDefines how colors are interpolated. Premultiplied is the default, see Remarks for more info.
Returns
- IGradientStopCollection
The new gradient stop collection.
Remarks
This method linearly interpolates between the color stops. An optional color space conversion is applied post-interpolation.
Whether and how this gamma conversion is applied is determined by the pre- and post-interpolation. This method will fail if
the device context does not support the requested buffer precision.
In order to get the desired result, you need to ensure that the inputs are specified in the correct color space.
You must always specify colors in straight alpha, regardless of interpolation mode being premultiplied or straight. The
interpolation mode only affects the interpolated values. Likewise, the stops returned by GradientStops
will always have straight alpha.
If you specify Premultiplied, then all stops are premultiplied before interpolation,
and then un-premultiplied before color conversion.
See ID2D1DeviceContext::CreateGradientStopCollection method
for a table showing the interpolation behavior with respect to the color space options.