This commit is contained in:
Scott Williams 2017-02-05 22:39:43 +00:00
Родитель 7a450e0fe3
Коммит 4f8f7d4181
4 изменённых файлов: 37 добавлений и 34 удалений

Просмотреть файл

@ -20,7 +20,6 @@ namespace SixLabors.Shapes.DrawShapesWithImageSharp
paths.SaveImage("Clipping", "RectangleWithTopClipped.png");
}
private static void SaveImage(this IShape shape, params string[] path)
{
var fullPath = System.IO.Path.GetFullPath(System.IO.Path.Combine("Output", System.IO.Path.Combine(path)));
@ -31,7 +30,10 @@ namespace SixLabors.Shapes.DrawShapesWithImageSharp
using (var img = new Image((int)Math.Ceiling(width), (int)Math.Ceiling(height)))
{
img.Fill(Color.DarkBlue);
// In ImageSharp.Drawing.Paths there is an extension method that takes in an IShape directly.
img.Fill(Color.HotPink, new ShapeRegion(shape));
img.Draw(Color.LawnGreen, 1, new ShapePath(shape));
//ensure directory exists
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fullPath));

Просмотреть файл

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SixLabors.Shapes.DrawShapesWithImageSharp
{
internal static class RectangleExtensions
{
/// <summary>
/// Converts a Shaper2D <see cref="SixLabors.Shapes.Rectangle"/> to an ImageSharp <see cref="Rectangle"/> by creating a <see cref="Rectangle"/> the entirely surrounds the source.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <returns>A <see cref="Rectangle"/> representation of this <see cref="SixLabors.Shapes.Rectangle"/></returns>
public static ImageSharp.Rectangle Convert(this SixLabors.Shapes.Rectangle source)
{
int left = (int)Math.Floor(source.Left);
int right = (int)Math.Ceiling(source.Right);
int top = (int)Math.Floor(source.Top);
int bottom = (int)Math.Ceiling(source.Bottom);
return new ImageSharp.Rectangle(left, top, right - left, bottom - top);
}
}
}

Просмотреть файл

@ -1,12 +1,11 @@
using System.Buffers;
/*
* NOTE : this file is note required to draw shapes with imagesharp in product
* just reference IamgeSharp.Drawing.Paths .
* */
using System.Buffers;
using System.Collections.Immutable;
using System.Numerics;
using ImageSharp.Drawing.Processors;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
using ImageSharp.Drawing;
namespace SixLabors.Shapes.DrawShapesWithImageSharp

Просмотреть файл

@ -1,16 +1,11 @@
// <copyright file="ShapeRegion.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
/*
* NOTE : this file is note required to draw shapes with imagesharp in product
* just reference IamgeSharp.Drawing.Paths .
* */
using System.Buffers;
using System.Collections.Immutable;
using System.Numerics;
using ImageSharp.Drawing.Processors;
using SixLabors.Shapes;
using ImageSharp.Drawing;
using System;
@ -108,21 +103,4 @@ namespace SixLabors.Shapes.DrawShapesWithImageSharp
}
}
}
internal static class RectangleExtensions
{
/// <summary>
/// Converts a Shaper2D <see cref="SixLabors.Shapes.Rectangle"/> to an ImageSharp <see cref="Rectangle"/> by creating a <see cref="Rectangle"/> the entirely surrounds the source.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <returns>A <see cref="Rectangle"/> representation of this <see cref="SixLabors.Shapes.Rectangle"/></returns>
public static ImageSharp.Rectangle Convert(this SixLabors.Shapes.Rectangle source)
{
int left = (int)Math.Floor(source.Left);
int right = (int)Math.Ceiling(source.Right);
int top = (int)Math.Floor(source.Top);
int bottom = (int)Math.Ceiling(source.Bottom);
return new ImageSharp.Rectangle(left, top, right - left, bottom - top);
}
}
}