Added curved edge support to torn edge effect

This commit is contained in:
Jaex 2017-05-15 09:50:14 +03:00
parent 895beeaba5
commit f2a3b80d60
2 changed files with 14 additions and 3 deletions

View file

@ -1286,7 +1286,7 @@ public static void FastBoxBlur(Bitmap bmp, int radius)
} }
} }
public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorStyles sides) public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges)
{ {
if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None) if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None)
{ {
@ -1375,7 +1375,15 @@ public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorSty
using (TextureBrush brush = new TextureBrush(img)) using (TextureBrush brush = new TextureBrush(img))
{ {
g.SetHighQuality(); g.SetHighQuality();
g.FillPolygon(brush, points.ToArray());
if (curvedEdges)
{
g.FillClosedCurve(brush, points.ToArray());
}
else
{
g.FillPolygon(brush, points.ToArray());
}
return result; return result;
} }

View file

@ -42,6 +42,9 @@ internal class TornEdge : ImageEffect
[DefaultValue(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)] [DefaultValue(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)]
public AnchorStyles Sides { get; set; } public AnchorStyles Sides { get; set; }
[DefaultValue(true)]
public bool CurvedEdges { get; set; }
public TornEdge() public TornEdge()
{ {
this.ApplyDefaultPropertyValues(); this.ApplyDefaultPropertyValues();
@ -49,7 +52,7 @@ public TornEdge()
public override Image Apply(Image img) public override Image Apply(Image img)
{ {
return ImageHelpers.TornEdges(img, Depth, Range, Sides); return ImageHelpers.TornEdges(img, Depth, Range, Sides, CurvedEdges);
} }
} }
} }