SkiaSharp.SKShader Class

Shaders specify the source color(s) for what is being drawn in the SKPaint.

See Also: SKShader

Syntax

public class SKShader : SKObject

Remarks

Shaders specify the source colors for what is being drawn. If a paint has no shader, then the paint's color is used. If the paint has a shader, then the shader's colors are used instead, but they are modulated by the paint's alpha. 

This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency without having to modify the original shader, only the paint's alpha needs to be modified.

Shaders are created by calling one of the static “Create” methods in the SKShader method that create a shader of the appropriate type.

Linear Gradient Shader

c# Example

var colors = new SKColor [] { new SKColor (0, 255, 255), new SKColor (255, 0, 255), new SKColor (255, 255, 0), new SKColor (0, 255, 255)};
var shader = SKShader.CreateLinearGradient (new SKPoint (0, 0), new SKPoint (255, 255), colors, null, SKShaderTileMode.Clamp);
var paint = new SKPaint () { Shader = shader };
canvas.DrawPaint (paint);

Radial Gradient Shader

c# Example

var colors = new SKColor [] {
    new SKColor (0, 0, 255),
    new SKColor (0, 255, 0)
};
var shader = SKShader.CreateRadialGradient (new SKPoint (128, 128), 180, colors, null, SKShaderTileMode.Clamp);
var paint = new SKPaint () {
    Shader = shader,
};
canvas.DrawPaint (paint);

Two-point Conical Gradient Shader

c# Example

var colors = new SKColor [] {
    new SKColor (0, 0, 255),
    new SKColor (0, 255, 0)
};
var shader = SKShader.CreateTwoPointConicalGradient (new SKPoint (128, 128), 128, new SKPoint (128, 16), 16, colors, null, SKShaderTileMode.Clamp);
var paint = new SKPaint () {
    Shader = shader,
};
canvas.DrawPaint (paint);

Sweep Gradient Shader

c# Example

var colors = new SKColor [] {
    new SKColor (0, 255, 255),
    new SKColor (255, 0, 255),
    new SKColor (255, 255, 0),
    new SKColor (0, 255, 255)
};
var shader = SKShader.CreateSweepGradient (new SKPoint (128, 128), colors, null);
var paint = new SKPaint () {
    Shader = shader
};
canvas.DrawPaint (paint);

Fractal Perlin Noise

c# Example

var shader = SKShader.CreatePerlinNoiseFractalNoise (0.5f, 0.5f, 4, 0);
var paint = new SKPaint () { Shader = shader };
canvas.DrawPaint (paint);

Turbulence Perlin Noise

c# Example

var turbulence = SKShader.CreatePerlinNoiseTurbulence (0.05f, 0.05f, 4, 0);
var paint = new SKPaint () { Shader = turbulence };
canvas.DrawPaint (paint);

Compose Shader

c# Example

var colors = new SKColor [] { new SKColor (0, 255, 255), new SKColor (255, 0, 255), new SKColor (255, 255, 0), new SKColor (0, 255, 255)};
var sweep = SKShader.CreateSweepGradient (new SKPoint (128, 128), colors, null);
var turbulence = SKShader.CreatePerlinNoiseTurbulence (0.05f, 0.05f, 4, 0);
var shader = SKShader.CreateCompose (sweep, turbulence);
var paint = new SKPaint () { Shader = shader };
canvas.DrawPaint (paint);

Requirements

Namespace: SkiaSharp
Assembly: SkiaSharp (in SkiaSharp.dll)
Assembly Versions: 1.0.0.0, 1.49.0.0, 1.52.0.0, 1.53.0.0, 1.54.0.0, 1.54.0.0, 1.55.0.0, 1.56.0.0, 1.57.0.0, 1.58.0.0, 1.59.0.0

The members of SkiaSharp.SKShader are listed below.

See Also: SKObject

Public Methods

static
CreateBitmap(SKBitmap, SKShaderTileMode, SKShaderTileMode) : SKShader
Creates a new shader that will draw with the specified bitmap.
static
CreateBitmap(SKBitmap, SKShaderTileMode, SKShaderTileMode, SKMatrix) : SKShader
Creates a new shader that will draw with the specified bitmap.
static
CreateColor(SKColor) : SKShader
Creates a new shader that just draws the specified color.
static
CreateColorFilter(SKShader, SKColorFilter) : SKShader
Creates a new shader that produces the same colors as invoking this shader and then applying the color filter.
static
CreateCompose(SKShader, SKShader) : SKShader
Create a new compose shader, which combines two shaders by the SKXferMode.SrcOver blend mode.
static
CreateCompose(SKShader, SKShader, SKBlendMode) : SKShader
Create a new compose shader, which combines two shaders by a blend mode.
static
CreateCompose(SKShader, SKShader, SKXferMode) : SKShader
Create a new compose shader, which combines two shaders by a transfer mode.
static
CreateEmpty() : SKShader
Creates a new "empty” shader that will not draw anything.
static
CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode) : SKShader
Creates a shader that generates a linear gradient between the two specified points.
static
CreateLinearGradient(SKPoint, SKPoint, SKColor[], Single[], SKShaderTileMode, SKMatrix) : SKShader
Creates a shader that generates a linear gradient between the two specified points.
static
CreateLocalMatrix(SKShader, SKMatrix) : SKShader
Creates a shader that first applies the specified matrix and then applies the shader.
static
CreatePerlinNoiseFractalNoise(Single, Single, Int32, Single) : SKShader
Creates a new shader that draws Perlin fractal noise.
static
CreatePerlinNoiseFractalNoise(Single, Single, Int32, Single, SKPointI) : SKShader
Creates a new shader that draws Perlin fractal noise.
static
CreatePerlinNoiseTurbulence(Single, Single, Int32, Single) : SKShader
Creates a new shader that draws Perlin turbulence noise.
static
CreatePerlinNoiseTurbulence(Single, Single, Int32, Single, SKPointI) : SKShader
Creates a new shader that draws Perlin turbulence noise.
static
CreateRadialGradient(SKPoint, Single, SKColor[], Single[], SKShaderTileMode) : SKShader
Creates a shader that generates a radial gradient given the center and radius.
static
CreateRadialGradient(SKPoint, Single, SKColor[], Single[], SKShaderTileMode, SKMatrix) : SKShader
Creates a shader that generates a radial gradient given the center and radius.
static
CreateSweepGradient(SKPoint, SKColor[], Single[]) : SKShader
Creates a shader that generates a sweep gradient given a center.
static
CreateSweepGradient(SKPoint, SKColor[], Single[], SKMatrix) : SKShader
Creates a shader that generates a sweep gradient given a center.
static
CreateTwoPointConicalGradient(SKPoint, Single, SKPoint, Single, SKColor[], Single[], SKShaderTileMode) : SKShader
Creates a shader that generates a conical gradient given two circles.
static
CreateTwoPointConicalGradient(SKPoint, Single, SKPoint, Single, SKColor[], Single[], SKShaderTileMode, SKMatrix) : SKShader
Creates a shader that generates a conical gradient given two circles.

Protected Methods

override
Dispose(Boolean)