Class Paint
What a drawing call puts on the canvas, and how it combines with what is there: the colors (from the subclass), the BlendMode, an Opacity, whether edges are antialiased, and for shapes an optional Blur. The kinds are SolidPaint, the gradients (LinearGradient, RadialGradient, ConicalGradient, SweepGradient), ImagePaint, NoisePaint, BlendPaint, ColorMatrixPaint and CustomPaint. A color converts to a solid paint where a paint is expected. A paint is an ITextPaint, so a paragraph's text style can carry it.
A paint other than a solid one has its own coordinates: LocalMatrix maps them into the canvas's local coordinates, so a gradient or an image turns and scales with the canvas transform, and further with its own matrix.
public abstract record Paint : ITextPaint, IEquatable<Paint>
- Inheritance
-
Paint
- Implements
- Derived
- Inherited Members
Examples
// A color converts to a SolidPaint. A paint also carries a blend mode, an opacity and whether edges are antialiased.
canvas.FillRect(new RectF(0, 0, 200, 100), Rgba8.White);
SolidPaint glaze = new(new RgbaF32(0.9f, 0.2f, 0.1f, 1)) { BlendMode = BlendMode.Multiply, Opacity = 0.6f };
canvas.FillCircle(new Vector2(60, 50), 40, glaze);
// Pixel art: no antialiasing, so every pixel is fully drawn or not at all.
canvas.FillCircle(new Vector2(150, 50), 30, new SolidPaint(Rgba8.Black) { Antialias = false });
Properties
Antialias
Gets a value indicating whether edges are antialiased: each pixel gets its exact covered area. When false, a pixel is drawn fully when its center is inside and not at all otherwise, for pixel art and masks that must stay binary. Defaults to true.
public bool Antialias { get; init; }
Property Value
BlendMode
Gets how the paint combines with the pixels under it. Defaults to SourceOver.
public BlendMode BlendMode { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not defined.
Blur
Gets a blur of the shape's coverage, applied before the paint is: a soft-edged shape, or with Outer a glow around it. It applies to shapes, paths and text, not to images. null (the default) draws sharp edges.
public MaskBlur? Blur { get; init; }
Property Value
Dither
Gets a value indicating whether colors are dithered when they are rounded to 8 bits: a 4×4 ordered pattern of less than half a level is added before rounding, which hides the banding of large soft gradients and never changes a flat area of an exact level. Only shaded paints on 8-bit targets dither; solid paints and deeper targets do not. Defaults to false, as in Skia.
public bool Dither { get; init; }
Property Value
LocalMatrix
Gets the transform from the paint's own coordinates to the canvas's local coordinates, applied before the canvas transform. A gradient's points, an image's pixels and noise's lattice are in paint coordinates, so this stretches a radial gradient into an ellipse or turns a pattern. A matrix that cannot be inverted draws nothing. A solid paint ignores it. Defaults to the identity.
public Matrix3x2 LocalMatrix { get; init; }
Property Value
Exceptions
- ArgumentException
An element is not finite.
Opacity
Gets the paint's opacity, 0 to 1, which multiplies its alpha. Defaults to 1.
public float Opacity { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 1.
Overprint
Gets which plates the paint prints on an ink canvas, as PDF's overprint: Off (the default) paints every plate, knocking out what is below; On only the inks the colour names; NonZero as On, leaving the plates of a CMYK colour's zero components alone (PDF's overprint mode 1). RGB canvases ignore it, as PDF viewers do by default.
public Overprint Overprint { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not defined.
Methods
WithColorMatrix(ColorMatrix)
Returns a paint that runs a color matrix on this paint's colors, as Skia's color-filtered shader: each color, with straight alpha, goes through the matrix and is clamped to 0 to 1. A solid paint gives a solid paint of the transformed color.
public Paint WithColorMatrix(ColorMatrix matrix)
Parameters
matrixColorMatrixThe matrix, as Egami's ColorMatrix operation uses it.
Returns
- Paint
The new paint, with this paint's blend mode, opacity, antialiasing, dithering and blur.
Operators
implicit operator Paint(Rgba8)
Converts a color to a SolidPaint.
public static implicit operator Paint(Rgba8 color)
Parameters
colorRgba8The color.
Returns
implicit operator Paint(RgbaF32)
Converts a float color to a SolidPaint.
public static implicit operator Paint(RgbaF32 color)
Parameters
colorRgbaF32The color.