Class CustomPaint
A paint whose colors come from C# code: override Shade(int, int, Span<PremulRgbaF32>, in Matrix3x2) to fill a row of premultiplied float colors. Rows are
shaded in parallel bands, so Shade(int, int, Span<PremulRgbaF32>, in Matrix3x2) must be thread-safe and must give a pixel the same color whichever band or
thread asks; then the result is the same at any core count. A backend that keeps vectors, such as a PDF page, cannot run C#
and draws the call through its raster fallback instead. Derive a record class from it.
public abstract record CustomPaint : Paint, ITextPaint, IEquatable<Paint>, IEquatable<CustomPaint>
- Inheritance
-
CustomPaint
- Implements
- Inherited Members
Examples
// Concentric rings from C#: a record class whose Shade fills one row of premultiplied colors. It runs on several threads at
// once, so it keeps no state.
public sealed record class Rings(float Spacing) : CustomPaint
{
public override void Shade(int y, int x, Span<PremulRgbaF32> row, in Matrix3x2 inverse)
{
for (int i = 0; i < row.Length; i++)
{
Vector2 p = Vector2.Transform(new Vector2(x + i + 0.5f, y + 0.5f), inverse);
float v = 0.5f + (0.5f * MathF.Cos(p.Length() * MathF.Tau / Spacing));
row[i] = new PremulRgbaF32(v, v * 0.6f, 0.2f, 1);
}
}
}
Constructors
CustomPaint()
Initializes a new instance of the CustomPaint class.
protected CustomPaint()
Methods
Shade(int, int, Span<PremulRgbaF32>, in Matrix3x2)
Fills one row of pixels: row[i] is the device pixel (x + i, y),
whose center (x + i + 0.5, y + 0.5) maps to paint coordinates through inverse. Colors are premultiplied:
each channel at most the alpha, all from 0 to 1.
public abstract void Shade(int y, int x, Span<PremulRgbaF32> row, in Matrix3x2 inverse)
Parameters
yintThe device row.
xintThe device column of the first pixel.
rowSpan<PremulRgbaF32>The colors to write, one per pixel.
inverseMatrix3x2The transform from device pixels to paint coordinates: the inverse of the local matrix then the canvas transform.