Table of Contents

Class DrawingCanvas

Namespace
SixLabors.ImageSharp.Drawing.Processing
Assembly
SixLabors.ImageSharp.Drawing.dll

Represents a drawing canvas over a frame target.

public abstract class DrawingCanvas : IDisposable
Inheritance
DrawingCanvas
Implements
Derived
Inherited Members

Properties

Bounds

Gets the local bounds of this canvas.

public abstract Rectangle Bounds { get; }

Property Value

Rectangle

SaveCount

Gets the number of saved states currently on the canvas stack.

public abstract int SaveCount { get; }

Property Value

int

Methods

Apply(IPath, Action<IImageProcessingContext>)

Applies an image-processing operation to a path region.

public abstract void Apply(IPath path, Action<IImageProcessingContext> operation)

Parameters

path IPath

The path region to process.

operation Action<IImageProcessingContext>

The image-processing operation to apply to the region.

Remarks

The operation affects only pixels covered by the supplied path.

Apply(PathBuilder, Action<IImageProcessingContext>)

Applies an image-processing operation to a region described by a path builder.

public abstract void Apply(PathBuilder pathBuilder, Action<IImageProcessingContext> operation)

Parameters

pathBuilder PathBuilder

The path builder describing the region to process.

operation Action<IImageProcessingContext>

The image-processing operation to apply to the region.

Apply(Rectangle, Action<IImageProcessingContext>)

Applies an image-processing operation to a local region.

public abstract void Apply(Rectangle region, Action<IImageProcessingContext> operation)

Parameters

region Rectangle

The local region to process.

operation Action<IImageProcessingContext>

The image-processing operation to apply to the region.

Clear(Brush)

Clears the whole canvas using the given brush and clear-style composition options.

public void Clear(Brush brush)

Parameters

brush Brush

Brush used to shade destination pixels during clear.

Clear(Brush, IPath)

Clears a path region using the given brush and clear-style composition options.

public abstract void Clear(Brush brush, IPath path)

Parameters

brush Brush

Brush used to shade destination pixels during clear.

path IPath

The path region to clear.

Clear(Brush, Rectangle)

Clears a local region using the given brush and clear-style composition options.

public void Clear(Brush brush, Rectangle region)

Parameters

brush Brush

Brush used to shade destination pixels during clear.

region Rectangle

Region to clear in local coordinates.

CreateRegion(Rectangle)

Creates a child canvas over a subregion in local coordinates.

public abstract DrawingCanvas CreateRegion(Rectangle region)

Parameters

region Rectangle

The child region in local coordinates.

Returns

DrawingCanvas

A child canvas with local origin at (0,0).

CreateScene()

Creates a retained backend scene from the drawing commands currently queued on this canvas.

public abstract DrawingBackendScene CreateScene()

Returns

DrawingBackendScene

A retained backend scene.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public abstract void Dispose()

Draw(Pen, IPath)

Draws a path outline in local coordinates using the given pen.

public abstract void Draw(Pen pen, IPath path)

Parameters

pen Pen

Pen used to generate the outline fill path.

path IPath

The path to stroke.

Draw(Pen, IPathCollection)

Draws all paths in a collection using the provided pen.

public void Draw(Pen pen, IPathCollection paths)

Parameters

pen Pen

Pen used to generate outlines.

paths IPathCollection

Path collection to stroke.

Draw(Pen, PathBuilder)

Draws a path outline built by the provided builder using the given pen.

public void Draw(Pen pen, PathBuilder pathBuilder)

Parameters

pen Pen

Pen used to generate the outline fill path.

pathBuilder PathBuilder

The path builder describing the path to stroke.

Draw(Pen, Rectangle)

Draws a rectangular outline using the provided pen.

public void Draw(Pen pen, Rectangle region)

Parameters

pen Pen

Pen used to generate the rectangle outline.

region Rectangle

Rectangle region to stroke.

DrawArc(Pen, PointF, SizeF, float, float, float)

Draws an arc outline using the provided pen.

public void DrawArc(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle)

Parameters

pen Pen

Pen used to generate the arc outline.

center PointF

Arc center point in local coordinates.

radius SizeF

Arc radii in local coordinates.

rotation float

Ellipse rotation in degrees.

startAngle float

Arc start angle in degrees.

sweepAngle float

Arc sweep angle in degrees.

DrawBezier(Pen, params PointF[])

Draws a cubic bezier outline using the provided pen.

public void DrawBezier(Pen pen, params PointF[] points)

Parameters

pen Pen

Pen used to generate the bezier outline.

points PointF[]

Bezier control points.

DrawEllipse(Pen, PointF, SizeF)

Draws an ellipse outline using the provided pen.

public void DrawEllipse(Pen pen, PointF center, SizeF size)

Parameters

pen Pen

Pen used to generate the ellipse outline.

center PointF

Ellipse center point in local coordinates.

size SizeF

Ellipse width and height in local coordinates.

DrawGlyphs(Brush, Pen, IEnumerable<GlyphPathCollection>)

Draws layered glyph geometry.

public abstract void DrawGlyphs(Brush brush, Pen pen, IEnumerable<GlyphPathCollection> glyphs)

Parameters

brush Brush

Brush used to fill glyph layers.

pen Pen

Pen used to outline dominant painted layers.

glyphs IEnumerable<GlyphPathCollection>

Layered glyph geometry to draw.

DrawImage(Image, Rectangle, RectangleF, IResampler?)

Draws an image source region into a destination rectangle.

public abstract void DrawImage(Image image, Rectangle sourceRect, RectangleF destinationRect, IResampler? sampler = null)

Parameters

image Image

The source image.

sourceRect Rectangle

The source rectangle within image.

destinationRect RectangleF

The destination rectangle in local canvas coordinates.

sampler IResampler

Optional resampler used when scaling or transforming the image. Defaults to Bicubic.

DrawLine(Pen, params PointF[])

Draws a polyline outline using the provided pen and drawing options.

public abstract void DrawLine(Pen pen, params PointF[] points)

Parameters

pen Pen

Pen used to generate the line outline.

points PointF[]

Polyline points.

DrawPie(Pen, PointF, SizeF, float, float)

Draws a pie sector outline using the provided pen.

public void DrawPie(Pen pen, PointF center, SizeF radius, float startAngle, float sweepAngle)

Parameters

pen Pen

Pen used to generate the pie outline.

center PointF

The center point of the pie sector in local coordinates.

radius SizeF

The x and y radii of the pie sector in local coordinates.

startAngle float

The start angle of the pie sector in degrees.

sweepAngle float

The sweep angle of the pie sector in degrees.

DrawPie(Pen, PointF, SizeF, float, float, float)

Draws a pie sector outline using the provided pen.

public void DrawPie(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle)

Parameters

pen Pen

Pen used to generate the pie outline.

center PointF

The center point of the pie sector in local coordinates.

radius SizeF

The x and y radii of the pie sector in local coordinates.

rotation float

Ellipse rotation in degrees.

startAngle float

The start angle of the pie sector in degrees.

sweepAngle float

The sweep angle of the pie sector in degrees.

DrawText(LineLayout, IPath, Brush?, Pen?)

Draws one prepared line layout along a path baseline onto this canvas.

public abstract void DrawText(LineLayout lineLayout, IPath path, Brush? brush, Pen? pen)

Parameters

lineLayout LineLayout

The prepared line layout to draw.

path IPath

The path used as the text baseline in local canvas coordinates.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

DrawText(LineLayout, PointF, Brush?, Pen?)

Draws one prepared line layout onto this canvas.

public abstract void DrawText(LineLayout lineLayout, PointF location, Brush? brush, Pen? pen)

Parameters

lineLayout LineLayout

The prepared line layout to draw.

location PointF

The drawing location in local canvas coordinates.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

DrawText(TextBlock, IPath, float, Brush?, Pen?)

Draws a prepared text block along a path baseline onto this canvas.

public abstract void DrawText(TextBlock textBlock, IPath path, float wrappingLength, Brush? brush, Pen? pen)

Parameters

textBlock TextBlock

The prepared text block to draw.

path IPath

The path used as the text baseline in local canvas coordinates.

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

DrawText(TextBlock, PointF, float, Brush?, Pen?)

Draws a prepared text block onto this canvas.

public abstract void DrawText(TextBlock textBlock, PointF location, float wrappingLength, Brush? brush, Pen? pen)

Parameters

textBlock TextBlock

The prepared text block to draw.

location PointF

The drawing location in local canvas coordinates.

wrappingLength float

The wrapping length in pixels. Use -1 to disable wrapping.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

DrawText(RichTextOptions, ReadOnlySpan<char>, IPath, Brush?, Pen?)

Draws text along a path baseline onto this canvas.

public abstract void DrawText(RichTextOptions textOptions, ReadOnlySpan<char> text, IPath path, Brush? brush, Pen? pen)

Parameters

textOptions RichTextOptions

The text rendering options.

text ReadOnlySpan<char>

The text to draw.

path IPath

The path used as the text baseline in local canvas coordinates.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

DrawText(RichTextOptions, ReadOnlySpan<char>, Brush?, Pen?)

Draws text onto this canvas.

public abstract void DrawText(RichTextOptions textOptions, ReadOnlySpan<char> text, Brush? brush, Pen? pen)

Parameters

textOptions RichTextOptions

The text rendering options.

text ReadOnlySpan<char>

The text to draw.

brush Brush

Optional brush used to fill glyphs.

pen Pen

Optional pen used to outline glyphs.

Fill(Brush)

Fills the whole canvas using the given brush.

public void Fill(Brush brush)

Parameters

brush Brush

Brush used to shade destination pixels.

Fill(Brush, IPath)

Fills a path in local coordinates using the given brush.

public abstract void Fill(Brush brush, IPath path)

Parameters

brush Brush

Brush used to shade covered pixels.

path IPath

The path to fill.

Fill(Brush, IPathCollection)

Fills all paths in a collection using the given brush.

public void Fill(Brush brush, IPathCollection paths)

Parameters

brush Brush

Brush used to shade covered pixels.

paths IPathCollection

Path collection to fill.

Fill(Brush, PathBuilder)

Fills a path built by the provided builder using the given brush.

public void Fill(Brush brush, PathBuilder pathBuilder)

Parameters

brush Brush

Brush used to shade covered pixels.

pathBuilder PathBuilder

The path builder describing the fill region.

Fill(Brush, Rectangle)

Fills a local region using the given brush.

public void Fill(Brush brush, Rectangle region)

Parameters

brush Brush

Brush used to shade destination pixels.

region Rectangle

Region to fill in local coordinates.

FillArc(Brush, PointF, SizeF, float, float, float)

Fills the closed arc shape produced by joining the arc endpoints with a straight line.

public void FillArc(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle)

Parameters

brush Brush

Brush used to shade covered pixels.

center PointF

Arc center point in local coordinates.

radius SizeF

Arc radii in local coordinates.

rotation float

Ellipse rotation in degrees.

startAngle float

Arc start angle in degrees.

sweepAngle float

Arc sweep angle in degrees.

FillEllipse(Brush, PointF, SizeF)

Fills an ellipse using the provided brush.

public void FillEllipse(Brush brush, PointF center, SizeF size)

Parameters

brush Brush

Brush used to shade covered pixels.

center PointF

Ellipse center point in local coordinates.

size SizeF

Ellipse width and height in local coordinates.

FillPie(Brush, PointF, SizeF, float, float)

Fills a pie sector using the provided brush.

public void FillPie(Brush brush, PointF center, SizeF radius, float startAngle, float sweepAngle)

Parameters

brush Brush

Brush used to shade covered pixels.

center PointF

The center point of the pie sector in local coordinates.

radius SizeF

The x and y radii of the pie sector in local coordinates.

startAngle float

The start angle of the pie sector in degrees.

sweepAngle float

The sweep angle of the pie sector in degrees.

FillPie(Brush, PointF, SizeF, float, float, float)

Fills a pie sector using the provided brush.

public void FillPie(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle)

Parameters

brush Brush

Brush used to shade covered pixels.

center PointF

The center point of the pie sector in local coordinates.

radius SizeF

The x and y radii of the pie sector in local coordinates.

rotation float

Ellipse rotation in degrees.

startAngle float

The start angle of the pie sector in degrees.

sweepAngle float

The sweep angle of the pie sector in degrees.

Flush()

Seals queued drawing commands into the canvas timeline.

public abstract void Flush()

MeasureText(RichTextOptions, ReadOnlySpan<char>)

Measures the full set of layout metrics for the supplied text.

public abstract TextMetrics MeasureText(RichTextOptions textOptions, ReadOnlySpan<char> text)

Parameters

textOptions RichTextOptions

The text shaping and layout options.

text ReadOnlySpan<char>

The text to measure.

Returns

TextMetrics

A TextMetrics value containing the metrics for the laid-out text.

RenderScene(DrawingBackendScene)

Renders a retained backend scene into this canvas target.

public abstract void RenderScene(DrawingBackendScene scene)

Parameters

scene DrawingBackendScene

The retained backend scene to render.

Restore()

Restores the most recently saved state.

public abstract void Restore()

Remarks

If the most recently saved state was created by a SaveLayer overload, the layer is closed in the recorded timeline. Actual composition happens during Dispose().

RestoreTo(int)

Restores to a specific save count.

public abstract void RestoreTo(int saveCount)

Parameters

saveCount int

The save count to restore to.

Remarks

State frames above saveCount are discarded, and the last discarded frame becomes the current state. If any discarded state was created by a SaveLayer overload, those layers are closed in the recorded timeline and composed during Dispose().

Save()

Saves the current drawing state on the state stack.

public abstract int Save()

Returns

int

The save count after the state has been pushed.

Remarks

This operation stores the current canvas state by reference. If the same DrawingOptions instance is mutated after Save(), those mutations are visible when restoring.

Save(DrawingOptions, params IPath[])

Saves the current drawing state and replaces the active state with the provided options and clip paths.

public abstract int Save(DrawingOptions options, params IPath[] clipPaths)

Parameters

options DrawingOptions

Drawing options for the new active state.

clipPaths IPath[]

Clip paths for the new active state.

Returns

int

The save count after the previous state has been pushed.

Remarks

The provided options instance is stored by reference. Mutating it after this call mutates the active/restored state behavior.

SaveLayer()

Saves the current drawing state and begins an isolated compositing layer over the whole canvas.

public int SaveLayer()

Returns

int

The save count after the layer state has been pushed.

SaveLayer(GraphicsOptions)

Saves the current drawing state and begins an isolated compositing layer over the whole canvas.

public int SaveLayer(GraphicsOptions layerOptions)

Parameters

layerOptions GraphicsOptions

Graphics options controlling how the layer is composited on restore.

Returns

int

The save count after the layer state has been pushed.

SaveLayer(GraphicsOptions, Rectangle)

Saves the current drawing state and begins an isolated compositing layer bounded to a subregion. Subsequent draw commands are recorded into that isolated logical layer. When Restore() closes the layer, it is recorded into the canvas timeline and later composed during Dispose() using the specified layerOptions.

public abstract int SaveLayer(GraphicsOptions layerOptions, Rectangle bounds)

Parameters

layerOptions GraphicsOptions

Graphics options controlling how the closed layer is composited against the parent canvas when the canvas timeline is rendered during Dispose().

bounds Rectangle

The local bounds of the layer. Only this region is allocated and composited.

Returns

int

The save count after the layer state has been pushed.

Remarks

The layer bounds are expressed in the current local coordinate system and are transformed with the active drawing transform when the layer is created. They limit allocation and compositing only; they do not change the canvas coordinate system used by commands recorded inside the layer.