Class DrawingCanvas<TPixel>
- Namespace
- SixLabors.ImageSharp.Drawing.Processing
- Assembly
- SixLabors.ImageSharp.Drawing.dll
A drawing canvas over a frame target.
public sealed class DrawingCanvas<TPixel> : DrawingCanvas, IDisposable where TPixel : unmanaged, IPixel<TPixel>
Type Parameters
TPixelThe pixel format.
- Inheritance
-
DrawingCanvas<TPixel>
- Implements
- Inherited Members
Constructors
DrawingCanvas(Configuration, DrawingOptions, ICanvasFrame<TPixel>, params IPath[])
Initializes a new instance of the DrawingCanvas<TPixel> class.
public DrawingCanvas(Configuration configuration, DrawingOptions options, ICanvasFrame<TPixel> targetFrame, params IPath[] clipPaths)
Parameters
configurationConfigurationThe active processing configuration.
optionsDrawingOptionsInitial drawing options for this canvas instance.
targetFrameICanvasFrame<TPixel>The destination frame.
clipPathsIPath[]Initial clip paths for this canvas instance.
DrawingCanvas(Configuration, DrawingOptions, IDrawingBackend, ICanvasFrame<TPixel>, params IPath[])
Initializes a new instance of the DrawingCanvas<TPixel> class with an explicit backend and initial state.
public DrawingCanvas(Configuration configuration, DrawingOptions options, IDrawingBackend backend, ICanvasFrame<TPixel> targetFrame, params IPath[] clipPaths)
Parameters
configurationConfigurationThe active processing configuration.
optionsDrawingOptionsInitial drawing options for this canvas instance.
backendIDrawingBackendThe drawing backend implementation.
targetFrameICanvasFrame<TPixel>The destination frame.
clipPathsIPath[]Initial clip paths for this canvas instance.
DrawingCanvas(Configuration, DrawingOptions, Buffer2DRegion<TPixel>, params IPath[])
Initializes a new instance of the DrawingCanvas<TPixel> class.
public DrawingCanvas(Configuration configuration, DrawingOptions options, Buffer2DRegion<TPixel> targetRegion, params IPath[] clipPaths)
Parameters
configurationConfigurationThe active processing configuration.
optionsDrawingOptionsInitial drawing options for this canvas instance.
targetRegionBuffer2DRegion<TPixel>The destination target region.
clipPathsIPath[]Initial clip paths for this canvas instance.
Properties
Bounds
Gets the local bounds of this canvas.
public override Rectangle Bounds { get; }
Property Value
SaveCount
Gets the number of saved states currently on the canvas stack.
public override int SaveCount { get; }
Property Value
Methods
Apply(IPath, Action<IImageProcessingContext>)
Applies an image-processing operation to a path region.
public override void Apply(IPath path, Action<IImageProcessingContext> operation)
Parameters
pathIPathThe path region to process.
operationAction<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 override void Apply(PathBuilder pathBuilder, Action<IImageProcessingContext> operation)
Parameters
pathBuilderPathBuilderThe path builder describing the region to process.
operationAction<IImageProcessingContext>The image-processing operation to apply to the region.
Apply(Rectangle, Action<IImageProcessingContext>)
Applies an image-processing operation to a local region.
public override void Apply(Rectangle region, Action<IImageProcessingContext> operation)
Parameters
regionRectangleThe local region to process.
operationAction<IImageProcessingContext>The image-processing operation to apply to the region.
Clear(Brush, IPath)
Clears a path region using the given brush and clear-style composition options.
public override void Clear(Brush brush, IPath path)
Parameters
brushBrushBrush used to shade destination pixels during clear.
pathIPathThe path region to clear.
CreateRegion(Rectangle)
Creates a child canvas over a subregion in local coordinates.
public override DrawingCanvas<TPixel> CreateRegion(Rectangle region)
Parameters
regionRectangleThe child region in local coordinates.
Returns
- DrawingCanvas<TPixel>
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 override DrawingBackendScene CreateScene()
Returns
- DrawingBackendScene
A retained backend scene.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public override void Dispose()
Draw(Pen, IPath)
Draws a path outline in local coordinates using the given pen.
public override void Draw(Pen pen, IPath path)
Parameters
DrawGlyphs(Brush, Pen, IEnumerable<GlyphPathCollection>)
Draws layered glyph geometry.
public override void DrawGlyphs(Brush brush, Pen pen, IEnumerable<GlyphPathCollection> glyphs)
Parameters
brushBrushBrush used to fill glyph layers.
penPenPen used to outline dominant painted layers.
glyphsIEnumerable<GlyphPathCollection>Layered glyph geometry to draw.
DrawImage(Image, Rectangle, RectangleF, IResampler?)
Draws an image source region into a destination rectangle.
public override void DrawImage(Image image, Rectangle sourceRect, RectangleF destinationRect, IResampler? sampler)
Parameters
imageImageThe source image.
sourceRectRectangleThe source rectangle within
image.destinationRectRectangleFThe destination rectangle in local canvas coordinates.
samplerIResamplerOptional resampler used when scaling or transforming the image. Defaults to Bicubic.
DrawImage(Image<TPixel>, Rectangle, RectangleF, IResampler?)
Draws an image source region into a destination rectangle.
public void DrawImage(Image<TPixel> image, Rectangle sourceRect, RectangleF destinationRect, IResampler? sampler = null)
Parameters
imageImage<TPixel>The source image.
sourceRectRectangleThe source rectangle within
image.destinationRectRectangleFThe destination rectangle in local canvas coordinates.
samplerIResamplerOptional resampler used when scaling or transforming the image. Defaults to Bicubic.
DrawLine(Pen, PointF, PointF)
Draws a two-point line segment using the provided pen and drawing options.
public void DrawLine(Pen pen, PointF start, PointF end)
Parameters
penPenPen used to generate the line outline.
startPointFLine start point.
endPointFLine end point.
DrawLine(Pen, params PointF[])
Draws a polyline outline using the provided pen and drawing options.
public override void DrawLine(Pen pen, params PointF[] points)
Parameters
DrawText(LineLayout, IPath, Brush?, Pen?)
Draws one prepared line layout along a path baseline onto this canvas.
public override void DrawText(LineLayout lineLayout, IPath path, Brush? brush, Pen? pen)
Parameters
lineLayoutLineLayoutThe prepared line layout to draw.
pathIPathThe path used as the text baseline in local canvas coordinates.
brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
DrawText(LineLayout, PointF, Brush?, Pen?)
Draws one prepared line layout onto this canvas.
public override void DrawText(LineLayout lineLayout, PointF location, Brush? brush, Pen? pen)
Parameters
lineLayoutLineLayoutThe prepared line layout to draw.
locationPointFThe drawing location in local canvas coordinates.
brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
DrawText(TextBlock, IPath, float, Brush?, Pen?)
Draws a prepared text block along a path baseline onto this canvas.
public override void DrawText(TextBlock textBlock, IPath path, float wrappingLength, Brush? brush, Pen? pen)
Parameters
textBlockTextBlockThe prepared text block to draw.
pathIPathThe path used as the text baseline in local canvas coordinates.
wrappingLengthfloatThe wrapping length in pixels. Use
-1to disable wrapping.brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
DrawText(TextBlock, PointF, float, Brush?, Pen?)
Draws a prepared text block onto this canvas.
public override void DrawText(TextBlock textBlock, PointF location, float wrappingLength, Brush? brush, Pen? pen)
Parameters
textBlockTextBlockThe prepared text block to draw.
locationPointFThe drawing location in local canvas coordinates.
wrappingLengthfloatThe wrapping length in pixels. Use
-1to disable wrapping.brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
DrawText(RichTextOptions, ReadOnlySpan<char>, IPath, Brush?, Pen?)
Draws text along a path baseline onto this canvas.
public override void DrawText(RichTextOptions textOptions, ReadOnlySpan<char> text, IPath path, Brush? brush, Pen? pen)
Parameters
textOptionsRichTextOptionsThe text rendering options.
textReadOnlySpan<char>The text to draw.
pathIPathThe path used as the text baseline in local canvas coordinates.
brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
DrawText(RichTextOptions, ReadOnlySpan<char>, Brush?, Pen?)
Draws text onto this canvas.
public override void DrawText(RichTextOptions textOptions, ReadOnlySpan<char> text, Brush? brush, Pen? pen)
Parameters
textOptionsRichTextOptionsThe text rendering options.
textReadOnlySpan<char>The text to draw.
brushBrushOptional brush used to fill glyphs.
penPenOptional pen used to outline glyphs.
Fill(Brush, IPath)
Fills a path in local coordinates using the given brush.
public override void Fill(Brush brush, IPath path)
Parameters
Flush()
Seals queued drawing commands into the canvas timeline.
public override void Flush()
MeasureText(RichTextOptions, ReadOnlySpan<char>)
Measures the full set of layout metrics for the supplied text.
public override TextMetrics MeasureText(RichTextOptions textOptions, ReadOnlySpan<char> text)
Parameters
textOptionsRichTextOptionsThe text shaping and layout options.
textReadOnlySpan<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 override void RenderScene(DrawingBackendScene scene)
Parameters
sceneDrawingBackendSceneThe retained backend scene to render.
Restore()
Restores the most recently saved state.
public override 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 override void RestoreTo(int saveCount)
Parameters
saveCountintThe 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 override 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 override int Save(DrawingOptions options, params IPath[] clipPaths)
Parameters
optionsDrawingOptionsDrawing options for the new active state.
clipPathsIPath[]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(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 override int SaveLayer(GraphicsOptions layerOptions, Rectangle bounds)
Parameters
layerOptionsGraphicsOptionsGraphics options controlling how the closed layer is composited against the parent canvas when the canvas timeline is rendered during Dispose().
boundsRectangleThe 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.