PathGradientBrush Class
A brush painting the colors of the vertices of a polygon and of a center point, mixed across the triangles between them: the colors of a shape described by its vertices (Gouraud shading).
public sealed class PathGradientBrush : BrushRemarks
Triangles. The polygon of PathGradientBrush.Points is cut into triangles from PathGradientBrush.Center: the triangle i has the vertices PathGradientBrush.Center, Points[i] and Points[(i + 1) mod n]. A position takes the color of the first of these triangles that contains it, edges included; a position no triangle contains has no color, and nothing is painted there, whatever the shape that is painted. When the center sees every edge of the polygon (a convex polygon around its center, a star around its middle), the triangles cover the polygon exactly once. A triangle whose three vertices are on one line contains nothing.
Colors. The color of a pixel is the color at the center of that pixel. In the triangle of the center c and of the points a and b, with the cross product u × v = ux vy - uy vx, the position p has the weights s = ((p - c) × (b - c)) / ((a - c) × (b - c)) for a and t = ((a - c) × (p - c)) / ((a - c) × (b - c)) for b, and is in the triangle when s >= 0, t >= 0 and s + t <= 1. The colors are converted to the pixel format of the frame first, then interpolated on alpha-premultiplied values, as the stops of a gradient: a = ac + s (aa - ac) + t (ab - ac) for alpha and the same for each premultiplied sample, divided by a, each rounded as floor(v + 1/2 + 2^-20). A point has exactly its color, and a brush whose colors are all the same paints exactly what a SolidBrush of that color paints inside the triangles.
Cost. Each pixel tests the triangles in order until one contains it (those that cannot, from their bounds, are skipped): the cost of a pixel grows with the number of points. The arithmetic uses + - * / only: the pixels are the same on every platform.
- Inheritance
BrushPathGradientBrush
Constructors
| Name | Description |
|---|---|
| PathGradientBrush(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>, PointD, Rgba64) | Initializes a new instance of the PathGradientBrush class. |
| PathGradientBrush(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>, Rgba64) | Initializes a new instance of the PathGradientBrush class whose center is the mean of its points. |
PathGradientBrush overloads
PathGradientBrush(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>, PointD, Rgba64)
PathGradientBrush.csInitializes a new instance of the PathGradientBrush class.
public PathGradientBrush(ReadOnlySpan<PointD> points, ReadOnlySpan<Rgba64> pointColors, PointD center, Rgba64 centerColor)Parameters
pointsReadOnlySpan<PointD>- The vertices of the polygon, in canvas coordinates; at least three. They are copied.
pointColorsReadOnlySpan<Rgba64>- The color of each point, with straight alpha, or one color for every point. They are copied.
centerPointD- The point all the triangles share, in canvas coordinates.
centerColorRgba64- The color of the center, with straight alpha.
Exceptions
ArgumentException- There are fewer than three points, the number of colors is neither one nor the number of points, or a coordinate is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216.
PathGradientBrush(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>, Rgba64)
PathGradientBrush.csInitializes a new instance of the PathGradientBrush class whose center is the mean of its points.
public PathGradientBrush(ReadOnlySpan<PointD> points, ReadOnlySpan<Rgba64> pointColors, Rgba64 centerColor)Parameters
pointsReadOnlySpan<PointD>- The vertices of the polygon, in canvas coordinates; at least three. They are copied.
pointColorsReadOnlySpan<Rgba64>- The color of each point, with straight alpha, or one color for every point. They are copied.
centerColorRgba64- The color of the center, with straight alpha.
Exceptions
ArgumentException- There are fewer than three points, the number of colors is neither one nor the number of points, or a coordinate is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216.
Properties
| Name | Description |
|---|---|
| Center | Gets the point all the triangles share. |
| CenterColor | Gets the color of the center, with straight alpha. |
| PointColors | Gets the color of each point, with straight alpha: as many as there are points. |
| Points | Gets the vertices of the polygon. |
| Transform | Gets the transformation that places the polygon on the canvas: the points are given before it is applied. Defaults to the identity. |
Center
PathGradientBrush.csCenterColor
PathGradientBrush.csPointColors
PathGradientBrush.csGets the color of each point, with straight alpha: as many as there are points.
public ReadOnlyMemory<Rgba64> PointColors { get; }Property value
Points
PathGradientBrush.csTransform
PathGradientBrush.csGets the transformation that places the polygon on the canvas: the points are given before it is applied. Defaults to the identity.
public AffineTransform Transform { get; init; }Property value
Remarks
The color of a pixel is the color the brush has, before the transformation, at the position the center of the pixel comes from. With a transformation that flattens the plane to a line or a point, the brush paints nothing.