public static PdnRegion GetOutline(this PdnRegion region, RectangleF bounds, float scalefactor) { GraphicsPath path = new GraphicsPath(); PdnRegion region2 = region.Clone(); Matrix scalematrix = new Matrix( bounds, new PointF[] { new PointF(bounds.Left, bounds.Top), new PointF(bounds.Right * scalefactor, bounds.Top), new PointF(bounds.Left, bounds.Bottom * scalefactor) }); region2.Transform(scalematrix); foreach (RectangleF rect in region2.GetRegionScans()) { path.AddRectangle(RectangleF.Inflate(rect, 1, 1)); } PdnRegion retval = new PdnRegion(path); retval.Exclude(region2); return(retval); }
/// <summary> /// Constructs an outline of the given region with the given bounds /// and scaling factor. /// </summary> /// <param name="region"> /// The selection to approximate. /// </param> /// <param name="bounds"> /// The boundaries of the image. /// </param> /// <param name="scalingMultiplier"> /// The amount to scale the size of the outline by. /// </param> public static PdnRegion ConstructOutline( this PdnRegion region, RectangleF bounds, float scalingMultiplier) { GraphicsPath path = new GraphicsPath(); PdnRegion newRegion = region.Clone(); //The size to scale the region by. Matrix scalematrix = new Matrix( bounds, new PointF[] { new PointF(bounds.Left, bounds.Top), new PointF(bounds.Right * scalingMultiplier, bounds.Top), new PointF(bounds.Left, bounds.Bottom * scalingMultiplier) }); newRegion.Transform(scalematrix); //Makes the new region slightly larger by inflating rectangles. foreach (RectangleF rect in newRegion.GetRegionScans()) { path.AddRectangle(RectangleF.Inflate(rect, 1, 1)); } //Subtracts the old region, leaving an outline from the expansion. PdnRegion result = new PdnRegion(path); result.Exclude(newRegion); return(result); }