Edit

Share via


SKShader.CreateLinearGradient Method

Definition

Overloads

Name Description
CreateLinearGradient(SKPoint, SKPoint, SKColor[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points.

CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points.

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode, SKMatrix)

Creates a shader that generates a linear gradient between the two specified points.

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, Single[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, Single[], SKShaderTileMode, SKMatrix)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

Examples

var info = new SKImageInfo(256, 256);
using (var surface = SKSurface.Create(info)) {
    SKCanvas canvas = surface.Canvas;

    canvas.Clear(SKColors.White);

    // create the shader
    var colors = new SKColor[] {
        new SKColor(0, 0, 255),
        new SKColor(0, 255, 0)
    };
    var shader = SKShader.CreateLinearGradient(
        new SKPoint(0, 0),
        new SKPoint(255, 255),
        colors,
        null,
        SKShaderTileMode.Clamp);

    // use the shader
    var paint = new SKPaint {
        Shader = shader
    };
    canvas.DrawPaint(paint);
}

The example above produces the following:

Linear Gradient

Remarks

Creates a shader that generates a linear gradient between the two specified points.

CreateLinearGradient(SKPoint, SKPoint, SKColor[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColor[] colors, SkiaSharp.SKShaderTileMode mode);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColor[]

The array colors to be distributed between the two points.

mode
SKShaderTileMode

The tiling mode.

Returns

Returns a new SKShader, or an empty shader on error. Never returns null.

Applies to

CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColor[] colors, float[] colorPos, SkiaSharp.SKShaderTileMode mode);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColor[]

The array colors to be distributed between the two points.

colorPos
Single[]

The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

mode
SKShaderTileMode

The tiling mode.

Returns

Returns a new SKShader, or an empty shader on error. Never returns null.

Applies to

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColorF[] colors, SkiaSharp.SKColorSpace colorspace, SkiaSharp.SKShaderTileMode mode);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColorF[]

The array of colors to be distributed between the two points.

colorspace
SKColorSpace

The color space for the gradient colors.

mode
SKShaderTileMode

The tiling mode.

Returns

Returns a new SKShader, or an empty shader on error.

Applies to

CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode, SKMatrix)

Creates a shader that generates a linear gradient between the two specified points.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColor[] colors, float[] colorPos, SkiaSharp.SKShaderTileMode mode, SkiaSharp.SKMatrix localMatrix);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColor[]

The array colors to be distributed between the two points.

colorPos
Single[]

The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

mode
SKShaderTileMode

The tiling mode.

localMatrix
SKMatrix

The matrix to apply before applying the shader.

Returns

Returns a new SKShader, or an empty shader on error. Never returns null.

Applies to

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, Single[], SKShaderTileMode)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColorF[] colors, SkiaSharp.SKColorSpace colorspace, float[] colorPos, SkiaSharp.SKShaderTileMode mode);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColorF[]

The array of colors to be distributed between the two points.

colorspace
SKColorSpace

The color space for the gradient colors.

colorPos
Single[]

The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

mode
SKShaderTileMode

The tiling mode.

Returns

Returns a new SKShader, or an empty shader on error.

Applies to

CreateLinearGradient(SKPoint, SKPoint, SKColorF[], SKColorSpace, Single[], SKShaderTileMode, SKMatrix)

Creates a shader that generates a linear gradient between the two specified points in a specified color space.

public static SkiaSharp.SKShader CreateLinearGradient(SkiaSharp.SKPoint start, SkiaSharp.SKPoint end, SkiaSharp.SKColorF[] colors, SkiaSharp.SKColorSpace colorspace, float[] colorPos, SkiaSharp.SKShaderTileMode mode, SkiaSharp.SKMatrix localMatrix);

Parameters

start
SKPoint

The start point for the gradient.

end
SKPoint

The end point for the gradient.

colors
SKColorF[]

The array of colors to be distributed between the two points.

colorspace
SKColorSpace

The color space for the gradient colors.

colorPos
Single[]

The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

mode
SKShaderTileMode

The tiling mode.

localMatrix
SKMatrix

The matrix to apply before applying the shader.

Returns

Returns a new SKShader, or an empty shader on error.

Applies to