Skip to content

Commit

Permalink
add some mor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Dec 31, 2024
1 parent 728126b commit 7e3acc1
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Imaging/FiltersAreas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,66 @@ internal static Bitmap GenerateFilter(Bitmap image,
return ImageStream.CombineBitmap(image, filterBitmap, 0, 0);
}

/// <summary>
/// Fills the area with color.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="shape">The shape.</param>
/// <param name="shapeParams">The shape parameters.</param>
/// <param name="startPoint">The optional starting point (top-left corner) of the rectangle. Defaults to (0, 0).</param>
/// <returns>
/// Generates a filter for a certain area
/// </returns>
/// <exception cref="System.ArgumentOutOfRangeException">filter - null
/// or
/// shape - null</exception>
internal static Bitmap FillAreaWithColor(
Bitmap image,
int width,
int height,
Color color,
MaskShape shape,
object shapeParams = null,
Point? startPoint = null)
{
// Validate input
if (image == null) throw new ArgumentNullException(nameof(image));

// Default start point
var actualStartPoint = startPoint ?? new Point(0, 0);

using Graphics g = Graphics.FromImage(image);
using Brush brush = new SolidBrush(color);

// Apply mask based on the specified shape
switch (shape)
{
case MaskShape.Rectangle:
g.FillRectangle(brush, new Rectangle(actualStartPoint, new Size(width, height)));
break;

case MaskShape.Circle:
g.FillEllipse(brush, new Rectangle(actualStartPoint, new Size(width, height)));
break;

case MaskShape.Polygon:
if (shapeParams is Point[] points)
{
g.FillPolygon(brush, points);
}
else
{
throw new ArgumentException("Invalid shape parameters for polygon mask.", nameof(shapeParams));
}
break;

default:
throw new ArgumentOutOfRangeException(nameof(shape), shape, "Unsupported shape type");
}

return image;
}
}
}

0 comments on commit 7e3acc1

Please sign in to comment.