Method DrawRectangle
DrawRectangle(Rectangle, Color32, double)
Draws the outline of the specified rectangle with a solid color and thickness. Uses default stroke settings: Miter, Butt, and Center.
public Canvas DrawRectangle(Rectangle rect, Color32 color, double thickness = 1)
Parameters
rectRectangleThe rectangle to outline.
colorColor32The stroke color.
thicknessdoubleThe stroke thickness in pixels. Must be greater than zero. Defaults to 1.
Returns
Examples
var canvas = new Canvas(image);
canvas.DrawRectangle(
Rectangle.FromSize(10, 10, 200, 100),
new Color32(0, 0, 0),
thickness: 2);
Exceptions
- ArgumentNullException
Thrown if
rectis null.- ArgumentOutOfRangeException
Thrown if
thicknessis less than or equal to zero.
DrawRectangle(Rectangle, Pen)
Draws the outline of the specified rectangle using the given pen.
public Canvas DrawRectangle(Rectangle rect, Pen pen)
Parameters
rectRectangleThe rectangle to outline.
penPenThe pen that defines the stroke color, thickness, line join, line cap, miter limit, and alignment.
Returns
Examples
var pen = new Pen(new Color32(255, 0, 0), 3)
{
LineJoin = LineJoin.Round,
Alignment = PenAlignment.Inside
};
var canvas = new Canvas(image);
canvas.DrawRectangle(Rectangle.FromSize(10, 10, 200, 100), pen);
Exceptions
- ArgumentNullException
Thrown if
rectorpenis null.