Brush Class

The colors a shape is painted with: a SolidBrush, a GradientBrush, a PathGradientBrush, an ImageBrush or a PatternBrush.

public abstract class Brush

Remarks

Brushes are immutable and thread-safe: create them once and reuse them (an ImageBrush refers to an image that is not, and a PatternBrush to a callback that draws). The type cannot be derived outside the library.

Brush colors are sample values in the color space of the image they are drawn on: no color profile is applied, unless the brush is used inside DrawingCanvas.PaintProfile, which says what profile the colors of the paints are colors of, and converts them. Before painting, a color is converted to the pixel format of the frame with the rules of Image.CloneAs (Rec. 709 luma on grayscale frames, rounding to 8 bits on 8-bit frames); its alpha stays the opacity of the paint, also on frames without alpha.

Properties

NameDescription
BlendModeGets how the color of the paint is mixed with the color of the pixels it is drawn on, before it is composited. Defaults to BlendMode.Normal.
CompositeModeGets how the paint is combined with the pixels it is drawn on. Defaults to CompositeMode.SourceOver.
OpacityGets the opacity of the paint, from 0 (nothing is painted) to 1 (the default): globalAlpha of the HTML canvas.

BlendMode

Brush.cs

Gets how the color of the paint is mixed with the color of the pixels it is drawn on, before it is composited. Defaults to BlendMode.Normal.

public BlendMode BlendMode { get; init; }

Property value

BlendMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined BlendMode.

Remarks

The blend mode changes the color of the paint, and Brush.CompositeMode then combines the paint with the pixels: BlendMode.Multiply with the default operator darkens the pixels by the paint.

CompositeMode

Brush.cs

Gets how the paint is combined with the pixels it is drawn on. Defaults to CompositeMode.SourceOver.

public CompositeMode CompositeMode { get; init; }

Property value

CompositeMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined CompositeMode.

Opacity

Brush.cs

Gets the opacity of the paint, from 0 (nothing is painted) to 1 (the default): globalAlpha of the HTML canvas.

public double Opacity { get; init; }

Property value

double

Exceptions

ArgumentOutOfRangeException
The value is not between 0 and 1.

Remarks

The opacity multiplies the alpha of the paint at each pixel, at the precision of the frame it is drawn on: an alpha a becomes floor(a opacity + 1/2 + 2^-20), before the paint is combined with the pixels by its Brush.CompositeMode and its Brush.BlendMode.

Methods

NameDescription
FromRgba32(Rgba32)Creates a brush painting a single color.
FromRgba64(Rgba64)Creates a brush painting a single color.

FromRgba32(Rgba32)

Brush.cs

Creates a brush painting a single color.

public static Brush FromRgba32(Rgba32 color)

Parameters

color Rgba32
The color, with straight alpha.

Returns

Brush A new SolidBrush.

FromRgba64(Rgba64)

Brush.cs

Creates a brush painting a single color.

public static Brush FromRgba64(Rgba64 color)

Parameters

color Rgba64
The color, with straight alpha.

Returns

Brush A new SolidBrush.

Operators

NameDescription
implicit operator Brush(Rgba32)Creates a brush painting a single color. A new SolidBrush is allocated by each conversion.
implicit operator Brush(Rgba64)Creates a brush painting a single color. A new SolidBrush is allocated by each conversion.

op_Implicit overloads

implicit operator Brush(Rgba32)

Brush.cs

Creates a brush painting a single color. A new SolidBrush is allocated by each conversion.

public static implicit operator Brush(Rgba32 color)
Parameters
color Rgba32
The color, with straight alpha.
Returns

Brush

implicit operator Brush(Rgba64)

Brush.cs

Creates a brush painting a single color. A new SolidBrush is allocated by each conversion.

public static implicit operator Brush(Rgba64 color)
Parameters
color Rgba64
The color, with straight alpha.
Returns

Brush