mirror of https://github.com/SixLabors/ImageSharp
14 changed files with 81 additions and 671 deletions
@ -1,112 +0,0 @@ |
|||||
// <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 Drawing; |
|
||||
using Drawing.Brushes; |
|
||||
using Drawing.Pens; |
|
||||
|
|
||||
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 image this method extends.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="pen">The pen.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</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 <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</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 <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="thickness">The thickness.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,78 +0,0 @@ |
|||||
// <copyright file="FillShape.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 Drawing; |
|
||||
using Drawing.Brushes; |
|
||||
|
|
||||
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 image this method extends.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The graphics options.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="brush">The brush.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <param name="options">The options.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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 image this method extends.</param>
|
|
||||
/// <param name="color">The color.</param>
|
|
||||
/// <param name="shape">The shape.</param>
|
|
||||
/// <returns>The <see cref="Image{TColor}"/>.</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); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,156 +0,0 @@ |
|||||
|
|
||||
namespace ImageSharp.Tests.Drawing.Paths |
|
||||
{ |
|
||||
using System; |
|
||||
using System.IO; |
|
||||
using ImageSharp; |
|
||||
using ImageSharp.Drawing.Brushes; |
|
||||
using Processing; |
|
||||
using System.Collections.Generic; |
|
||||
using Xunit; |
|
||||
using ImageSharp.Drawing; |
|
||||
using System.Numerics; |
|
||||
using SixLabors.Shapes; |
|
||||
using ImageSharp.Drawing.Processors; |
|
||||
using ImageSharp.Drawing.Pens; |
|
||||
|
|
||||
public class DrawShape: IDisposable |
|
||||
{ |
|
||||
float thickness = 7.2f; |
|
||||
GraphicsOptions noneDefault = new GraphicsOptions(); |
|
||||
Color color = Color.HotPink; |
|
||||
SolidBrush brush = Brushes.Solid(Color.HotPink); |
|
||||
Pen pen = new Pen(Color.Gray, 99.9f); |
|
||||
IShape shape = new SixLabors.Shapes.Polygon(new LinearLineSegment(new Vector2[] { |
|
||||
new Vector2(10,10), |
|
||||
new Vector2(20,10), |
|
||||
new Vector2(20,10), |
|
||||
new Vector2(30,10), |
|
||||
})); |
|
||||
private ProcessorWatchingImage img; |
|
||||
|
|
||||
public DrawShape() |
|
||||
{ |
|
||||
this.img = new Paths.ProcessorWatchingImage(10, 10); |
|
||||
} |
|
||||
|
|
||||
public void Dispose() |
|
||||
{ |
|
||||
img.Dispose(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsBrushThicknessAndShape() |
|
||||
{ |
|
||||
img.Draw(brush, thickness, shape); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|
||||
Assert.Equal(brush, pen.Brush); |
|
||||
Assert.Equal(thickness, pen.Width); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsBrushThicknessShapeAndOptions() |
|
||||
{ |
|
||||
img.Draw(brush, thickness, shape, noneDefault); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(noneDefault, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|
||||
Assert.Equal(brush, pen.Brush); |
|
||||
Assert.Equal(thickness, pen.Width); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsColorThicknessAndShape() |
|
||||
{ |
|
||||
img.Draw(color, thickness, shape); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|
||||
Assert.Equal(thickness, pen.Width); |
|
||||
|
|
||||
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|
||||
Assert.Equal(color, brush.Color); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsColorThicknessShapeAndOptions() |
|
||||
{ |
|
||||
img.Draw(color, thickness, shape, noneDefault); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(noneDefault, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|
||||
Assert.Equal(thickness, pen.Width); |
|
||||
|
|
||||
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|
||||
Assert.Equal(color, brush.Color); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsPenAndShape() |
|
||||
{ |
|
||||
img.Draw(pen, shape); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Assert.Equal(pen, processor.Pen); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsPenShapeAndOptions() |
|
||||
{ |
|
||||
img.Draw(pen, shape, noneDefault); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(noneDefault, processor.Options); |
|
||||
|
|
||||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|
||||
Assert.NotEmpty(shapepath.Paths); |
|
||||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|
||||
|
|
||||
Assert.Equal(pen, processor.Pen); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,107 +0,0 @@ |
|||||
|
|
||||
namespace ImageSharp.Tests.Drawing.Paths |
|
||||
{ |
|
||||
using System; |
|
||||
using System.IO; |
|
||||
using ImageSharp; |
|
||||
using ImageSharp.Drawing.Brushes; |
|
||||
using Processing; |
|
||||
using System.Collections.Generic; |
|
||||
using Xunit; |
|
||||
using ImageSharp.Drawing; |
|
||||
using System.Numerics; |
|
||||
using SixLabors.Shapes; |
|
||||
using ImageSharp.Drawing.Processors; |
|
||||
using ImageSharp.Drawing.Pens; |
|
||||
|
|
||||
public class FillShape : IDisposable |
|
||||
{ |
|
||||
GraphicsOptions noneDefault = new GraphicsOptions(); |
|
||||
Color color = Color.HotPink; |
|
||||
SolidBrush brush = Brushes.Solid(Color.HotPink); |
|
||||
IShape shape = new Polygon(new LinearLineSegment(new Vector2[] { |
|
||||
new Vector2(10,10), |
|
||||
new Vector2(20,10), |
|
||||
new Vector2(20,10), |
|
||||
new Vector2(30,10), |
|
||||
})); |
|
||||
private ProcessorWatchingImage img; |
|
||||
|
|
||||
public FillShape() |
|
||||
{ |
|
||||
this.img = new Paths.ProcessorWatchingImage(10, 10); |
|
||||
} |
|
||||
|
|
||||
public void Dispose() |
|
||||
{ |
|
||||
img.Dispose(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsBrushAndShape() |
|
||||
{ |
|
||||
img.Fill(brush, shape); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
FillRegionProcessor<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|
||||
|
|
||||
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); |
|
||||
Assert.Equal(shape, region.Shape); |
|
||||
|
|
||||
Assert.Equal(brush, processor.Brush); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsBrushShapeAndOptions() |
|
||||
{ |
|
||||
img.Fill(brush, shape, noneDefault); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
FillRegionProcessor<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(noneDefault, processor.Options); |
|
||||
|
|
||||
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); |
|
||||
Assert.Equal(shape, region.Shape); |
|
||||
|
|
||||
Assert.Equal(brush, processor.Brush); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsColorAndShape() |
|
||||
{ |
|
||||
img.Fill(color, shape); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
FillRegionProcessor<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|
||||
|
|
||||
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); |
|
||||
Assert.Equal(shape, region.Shape); |
|
||||
|
|
||||
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(processor.Brush); |
|
||||
Assert.Equal(color, brush.Color); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void CorrectlySetsColorShapeAndOptions() |
|
||||
{ |
|
||||
img.Fill(color, shape, noneDefault); |
|
||||
|
|
||||
Assert.NotEmpty(img.ProcessorApplications); |
|
||||
FillRegionProcessor<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|
||||
|
|
||||
Assert.Equal(noneDefault, processor.Options); |
|
||||
|
|
||||
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region); |
|
||||
Assert.Equal(shape, region.Shape); |
|
||||
|
|
||||
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(processor.Brush); |
|
||||
Assert.Equal(color, brush.Color); |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue