mirror of https://github.com/SixLabors/ImageSharp
37 changed files with 1509 additions and 823 deletions
@ -0,0 +1,120 @@ |
|||||
|
// <copyright file="DrawBeziers.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
using Path = SixLabors.Shapes.Path; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points))); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path with the supplied pen
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new Path(new BezierLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Bezier path with the supplied pen
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new Path(new BezierLineSegment(points))); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,120 @@ |
|||||
|
// <copyright file="DrawLines.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
using Path = SixLabors.Shapes.Path; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points))); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path with the supplied pen
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new Path(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as an open Linear path with the supplied pen
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new Path(new LinearLineSegment(points))); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,124 @@ |
|||||
|
// <copyright file="DrawPath.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new ShapePath(path), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, path, GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The shape.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), path, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), path); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, path); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
// <copyright file="DrawPolygon.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points))); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,118 @@ |
|||||
|
// <copyright file="DrawShape.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, new ShapePath(shape), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, shape, GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), shape, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), shape); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, shape, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, shape); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,87 @@ |
|||||
|
// <copyright file="FillPaths.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Processors; |
||||
|
|
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="path">The shape.</param>
|
||||
|
/// <param name="options">The graphics options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new ShapeRegion(path), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), path, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), path); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
// <copyright file="FillPolygon.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Processors; |
||||
|
|
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of a Linear polygon described by the points
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of a Linear polygon described by the points
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new Polygon(new LinearLineSegment(points))); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of a Linear polygon described by the points
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of a Linear polygon described by the points
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="points">The points.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points))); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
// <copyright file="FillShapes.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Processors; |
||||
|
|
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <param name="options">The graphics options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new ShapeRegion(shape), options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), shape, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image in the shape of the provided polygon with the specified brush..
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), shape); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<PropertyGroup> |
||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> |
||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>e5bd4f96-28a8-410c-8b63-1c5731948549</ProjectGuid> |
||||
|
<RootNamespace>ImageSharp.Drawing</RootNamespace> |
||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> |
||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> |
||||
|
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup> |
||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |
||||
|
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> |
||||
|
</PropertyGroup> |
||||
|
<ItemGroup> |
||||
|
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
</Project> |
||||
@ -0,0 +1,6 @@ |
|||||
|
// <copyright file="AssemblyInfo.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
// Common values read from `AssemblyInfo.Common.cs`
|
||||
@ -0,0 +1,137 @@ |
|||||
|
// <copyright file="ShapeRegion.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Drawing |
||||
|
{ |
||||
|
using System.Buffers; |
||||
|
using System.Collections.Immutable; |
||||
|
using System.Numerics; |
||||
|
|
||||
|
using ImageSharp.Drawing.Processors; |
||||
|
|
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
using Rectangle = ImageSharp.Rectangle; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
|
||||
|
/// </summary>
|
||||
|
internal class ShapeRegion : Region |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The fillable shape
|
||||
|
/// </summary>
|
||||
|
private readonly IShape shape; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
public ShapeRegion(IPath path) |
||||
|
: this(path.AsShape()) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="shape">The shape.</param>
|
||||
|
public ShapeRegion(IShape shape) |
||||
|
{ |
||||
|
this.shape = shape; |
||||
|
this.Bounds = shape.Bounds.Convert(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the maximum number of intersections to could be returned.
|
||||
|
/// </summary>
|
||||
|
/// <value>
|
||||
|
/// The maximum intersections.
|
||||
|
/// </value>
|
||||
|
public override int MaxIntersections => this.shape.MaxIntersections; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the bounds.
|
||||
|
/// </summary>
|
||||
|
/// <value>
|
||||
|
/// The bounds.
|
||||
|
/// </value>
|
||||
|
public override Rectangle Bounds { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Scans the X axis for intersections.
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The x.</param>
|
||||
|
/// <param name="buffer">The buffer.</param>
|
||||
|
/// <param name="length">The length.</param>
|
||||
|
/// <param name="offset">The offset.</param>
|
||||
|
/// <returns>
|
||||
|
/// The number of intersections found.
|
||||
|
/// </returns>
|
||||
|
public override int ScanX(int x, float[] buffer, int length, int offset) |
||||
|
{ |
||||
|
var start = new Vector2(x, this.Bounds.Top - 1); |
||||
|
var end = new Vector2(x, this.Bounds.Bottom + 1); |
||||
|
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); |
||||
|
try |
||||
|
{ |
||||
|
int count = this.shape.FindIntersections( |
||||
|
start, |
||||
|
end, |
||||
|
innerbuffer, |
||||
|
length, |
||||
|
0); |
||||
|
|
||||
|
for (var i = 0; i < count; i++) |
||||
|
{ |
||||
|
buffer[i + offset] = innerbuffer[i].Y; |
||||
|
} |
||||
|
|
||||
|
return count; |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
ArrayPool<Vector2>.Shared.Return(innerbuffer); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Scans the Y axis for intersections.
|
||||
|
/// </summary>
|
||||
|
/// <param name="y">The position along the y axis to find intersections.</param>
|
||||
|
/// <param name="buffer">The buffer.</param>
|
||||
|
/// <param name="length">The length.</param>
|
||||
|
/// <param name="offset">The offset.</param>
|
||||
|
/// <returns>
|
||||
|
/// The number of intersections found.
|
||||
|
/// </returns>
|
||||
|
public override int ScanY(int y, float[] buffer, int length, int offset) |
||||
|
{ |
||||
|
var start = new Vector2(float.MinValue, y); |
||||
|
var end = new Vector2(float.MaxValue, y); |
||||
|
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); |
||||
|
try |
||||
|
{ |
||||
|
int count = this.shape.FindIntersections( |
||||
|
start, |
||||
|
end, |
||||
|
innerbuffer, |
||||
|
length, |
||||
|
0); |
||||
|
|
||||
|
for (var i = 0; i < count; i++) |
||||
|
{ |
||||
|
buffer[i + offset] = innerbuffer[i].X; |
||||
|
} |
||||
|
|
||||
|
return count; |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
ArrayPool<Vector2>.Shared.Return(innerbuffer); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,96 @@ |
|||||
|
{ |
||||
|
"version": "1.0.0-alpha1-*", |
||||
|
"title": "ImageSharp.Drawing.Paths", |
||||
|
"description": "A cross-platform library for the processing of image files; written in C#", |
||||
|
"authors": [ |
||||
|
"James Jackson-South and contributors" |
||||
|
], |
||||
|
"packOptions": { |
||||
|
"owners": [ |
||||
|
"James Jackson-South and contributors" |
||||
|
], |
||||
|
"projectUrl": "https://github.com/JimBobSquarePants/ImageSharp", |
||||
|
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", |
||||
|
"iconUrl": "https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png", |
||||
|
"requireLicenseAcceptance": false, |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/JimBobSquarePants/ImageSharp" |
||||
|
}, |
||||
|
"tags": [ |
||||
|
"Image Resize Crop Gif Jpg Jpeg Bitmap Png Core" |
||||
|
] |
||||
|
}, |
||||
|
"buildOptions": { |
||||
|
"allowUnsafe": true, |
||||
|
"xmlDoc": true, |
||||
|
"additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], |
||||
|
"compile": [ |
||||
|
"../Shared/*.cs" |
||||
|
] |
||||
|
}, |
||||
|
"configurations": { |
||||
|
"Release": { |
||||
|
"buildOptions": { |
||||
|
"warningsAsErrors": true, |
||||
|
"optimize": true |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
"ImageSharp": { |
||||
|
"target": "project" |
||||
|
}, |
||||
|
"ImageSharp.Drawing": { |
||||
|
"target": "project" |
||||
|
}, |
||||
|
"SixLabors.Shapes": "0.1.0-ci0050", |
||||
|
"StyleCop.Analyzers": { |
||||
|
"version": "1.0.0", |
||||
|
"type": "build" |
||||
|
}, |
||||
|
"System.Buffers": "4.0.0", |
||||
|
"System.Runtime.CompilerServices.Unsafe": "4.0.0" |
||||
|
}, |
||||
|
"frameworks": { |
||||
|
"netstandard1.1": { |
||||
|
"dependencies": { |
||||
|
"System.Collections": "4.0.11", |
||||
|
"System.Diagnostics.Debug": "4.0.11", |
||||
|
"System.Diagnostics.Tools": "4.0.1", |
||||
|
"System.IO": "4.1.0", |
||||
|
"System.IO.Compression": "4.1.0", |
||||
|
"System.Linq": "4.1.0", |
||||
|
"System.Numerics.Vectors": "4.1.1", |
||||
|
"System.ObjectModel": "4.0.12", |
||||
|
"System.Resources.ResourceManager": "4.0.1", |
||||
|
"System.Runtime.Extensions": "4.1.0", |
||||
|
"System.Runtime.InteropServices": "4.1.0", |
||||
|
"System.Runtime.Numerics": "4.0.1", |
||||
|
"System.Text.Encoding.Extensions": "4.0.11", |
||||
|
"System.Threading": "4.0.11", |
||||
|
"System.Threading.Tasks": "4.0.11", |
||||
|
"System.Threading.Tasks.Parallel": "4.0.1" |
||||
|
} |
||||
|
}, |
||||
|
"net45": { |
||||
|
"dependencies": { |
||||
|
"System.Numerics.Vectors": "4.1.1", |
||||
|
"System.Threading.Tasks.Parallel": "4.0.0" |
||||
|
}, |
||||
|
"frameworkAssemblies": { |
||||
|
"System.Runtime": { "type": "build" } |
||||
|
} |
||||
|
}, |
||||
|
"net461": { |
||||
|
"dependencies": { |
||||
|
"System.Threading.Tasks.Parallel": "4.0.0" |
||||
|
}, |
||||
|
"frameworkAssemblies": { |
||||
|
"System.Runtime": { "type": "build" }, |
||||
|
"System.Numerics": "4.0.0.0", |
||||
|
"System.Numerics.Vectors": "4.0.0.0" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,506 +0,0 @@ |
|||||
// <copyright file="Draw.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp |
|
||||
{ |
|
||||
using System; |
|
||||
using System.Numerics; |
|
||||
using Drawing; |
|
||||
using Drawing.Brushes; |
|
||||
using Drawing.Pens; |
|
||||
using Drawing.Processors; |
|
||||
using SixLabors.Shapes; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
|
||||
/// </summary>
|
|
||||
public static partial class ImageExtensions |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(shape), options)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(pen, shape, GraphicsOptions.Default); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the provided pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(path), options)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the provided pen.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(path), GraphicsOptions.Default)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the bursh at the privdied thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), path, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the bursh at the privdied thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), path); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the bursh at the privdied thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the path with the bursh at the privdied thickness.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="path">The path.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path with the supplied pen
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(pen, new Path(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Linear path with the supplied pen
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(pen, new Path(new LinearLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path with the supplied pen
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(pen, new Path(new BezierLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Draws the provided Points as an open Bezier path with the supplied pen
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.DrawPath(pen, new Path(new BezierLineSegment(points))); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,123 @@ |
|||||
|
// <copyright file="DrawPath.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Pens; |
||||
|
using Drawing.Processors; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the region with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Apply(new DrawPathProcessor<TColor>(pen, path, options)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided pen.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(pen, path, GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), path, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new Pen<TColor>(brush, thickness), path); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Draws the outline of the polygon with the provided brush at the provided thickness.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="thickness">The thickness.</param>
|
||||
|
/// <param name="path">The path.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Draw(new SolidBrush<TColor>(color), thickness, path); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,173 +0,0 @@ |
|||||
// <copyright file="Fill.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp |
|
||||
{ |
|
||||
using System; |
|
||||
using System.Numerics; |
|
||||
using Drawing; |
|
||||
using Drawing.Brushes; |
|
||||
using Drawing.Processors; |
|
||||
|
|
||||
using SixLabors.Shapes; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
|
||||
/// </summary>
|
|
||||
public static partial class ImageExtensions |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Flood fills the image with the specified brush.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new FillProcessor<TColor>(brush)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image with the specified color.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Fill(new SolidBrush<TColor>(color)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The graphics options.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new FillShapeProcessor<TColor>(brush, new ShapeRegion(shape), options)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape of the provided polygon with the specified brush.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Apply(new FillShapeProcessor<TColor>(brush, new ShapeRegion(shape), GraphicsOptions.Default)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Fill(new SolidBrush<TColor>(color), shape, options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
return source.Fill(new SolidBrush<TColor>(color), shape); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape of a Linear polygon described by the points
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
// using Polygon directly instead of LinearPolygon as its will have less indirection
|
|
||||
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape of a Linear polygon described by the points
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
// using Polygon directly instead of LinearPolygon as its will have less indirection
|
|
||||
return source.Fill(brush, new Polygon(new LinearLineSegment(points))); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape of a Linear polygon described by the points
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>
|
|
||||
/// The Image
|
|
||||
/// </returns>
|
|
||||
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
// using Polygon directly instead of LinearPolygon as its will have less indirection
|
|
||||
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Flood fills the image in the shape of a Linear polygon described by the points
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TColor">The type of the color.</typeparam>
|
|
||||
/// <param name="source">The source.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="points">The points.</param>
|
|
||||
/// <returns>The Image</returns>
|
|
||||
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points) |
|
||||
where TColor : struct, IPackedPixel, IEquatable<TColor> |
|
||||
{ |
|
||||
// using Polygon directly instead of LinearPolygon as its will have less indirection
|
|
||||
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points))); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,111 @@ |
|||||
|
// <copyright file="FillRegion.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using Drawing; |
||||
|
using Drawing.Brushes; |
||||
|
using Drawing.Processors; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
||||
|
/// </summary>
|
||||
|
public static partial class ImageExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with the specified brush.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Apply(new FillProcessor<TColor>(brush)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with the specified color.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <returns>The Image</returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with in the region with the specified brush.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="region">The region.</param>
|
||||
|
/// <param name="options">The graphics options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Apply(new FillRegionProcessor<TColor>(brush, region, options)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with in the region with the specified brush.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="brush">The brush.</param>
|
||||
|
/// <param name="region">The region.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(brush, region, GraphicsOptions.Default); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with in the region with the specified color.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="region">The region.</param>
|
||||
|
/// <param name="options">The options.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region, GraphicsOptions options) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), region, options); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Flood fills the image with in the region with the specified color.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TColor">The type of the color.</typeparam>
|
||||
|
/// <param name="source">The source.</param>
|
||||
|
/// <param name="color">The color.</param>
|
||||
|
/// <param name="region">The region.</param>
|
||||
|
/// <returns>
|
||||
|
/// The Image
|
||||
|
/// </returns>
|
||||
|
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region) |
||||
|
where TColor : struct, IPackedPixel, IEquatable<TColor> |
||||
|
{ |
||||
|
return source.Fill(new SolidBrush<TColor>(color), region); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,24 +0,0 @@ |
|||||
// <copyright file="IDrawableRegion.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp.Drawing |
|
||||
{ |
|
||||
using System.Numerics; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Represents a region with knowledge about its outline.
|
|
||||
/// </summary>
|
|
||||
/// <seealso cref="ImageSharp.Drawing.IRegion" />
|
|
||||
public interface IDrawableRegion : IRegion |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Gets the point information for the specified x and y location.
|
|
||||
/// </summary>
|
|
||||
/// <param name="x">The x.</param>
|
|
||||
/// <param name="y">The y.</param>
|
|
||||
/// <returns>Information about the point in relation to a drawable edge</returns>
|
|
||||
PointInfo GetPointInfo(int x, int y); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,57 @@ |
|||||
|
// <copyright file="Path.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Drawing |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents a something that has knowledge about its outline.
|
||||
|
/// </summary>
|
||||
|
public abstract class Path |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the maximum number of intersections to could be returned.
|
||||
|
/// </summary>
|
||||
|
/// <value>
|
||||
|
/// The maximum intersections.
|
||||
|
/// </value>
|
||||
|
public abstract int MaxIntersections { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the bounds.
|
||||
|
/// </summary>
|
||||
|
/// <value>
|
||||
|
/// The bounds.
|
||||
|
/// </value>
|
||||
|
public abstract Rectangle Bounds { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the point information for the specified x and y location.
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The x.</param>
|
||||
|
/// <param name="y">The y.</param>
|
||||
|
/// <returns>Information about the point in relation to a drawable edge</returns>
|
||||
|
public abstract PointInfo GetPointInfo(int x, int y); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Scans the X axis for intersections.
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The x.</param>
|
||||
|
/// <param name="buffer">The buffer.</param>
|
||||
|
/// <param name="length">The length.</param>
|
||||
|
/// <param name="offset">The offset.</param>
|
||||
|
/// <returns>The number of intersections found.</returns>
|
||||
|
public abstract int ScanX(int x, float[] buffer, int length, int offset); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Scans the Y axis for intersections.
|
||||
|
/// </summary>
|
||||
|
/// <param name="y">The position along the y axis to find intersections.</param>
|
||||
|
/// <param name="buffer">The buffer.</param>
|
||||
|
/// <param name="length">The length.</param>
|
||||
|
/// <param name="offset">The offset.</param>
|
||||
|
/// <returns>The number of intersections found.</returns>
|
||||
|
public abstract int ScanY(int y, float[] buffer, int length, int offset); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue